I got it counting 0-9 then I added a pot for a little more fun.
Here is the sketch that allows you to turn the pot to set the digit displayed.
int num_array[10][7] = { { 0,0,0,0,1,0,0 }, // 0
{ 0,0,1,1,1,1,1 }, // 1
{ 1,0,0,1,0,0,0 }, // 2
{ 0,0,0,1,0,1,0 }, // 3
{ 0,0,1,0,0,1,1 }, // 4
{ 0,1,0,0,0,1,0 }, // 5
{ 0,1,0,0,0,0,0 }, // 6
{ 0,0,0,1,1,1,1 }, // 7
{ 0,0,0,0,0,0,0 }, // 8
{ 0,0,0,0,0,1,0 }}; // 9
#define POT A0
void setup()
{
// set pin modes
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int setNum = analogRead(POT);
setNum = map(setNum,0,1023,0,10);
Serial.println(setNum);
if(setNum<10) Num_Write(setNum);
}
// this functions writes values to the sev seg pins
void Num_Write(int number)
{
int pin= 2;
for (int j=0; j < 7; j++) {
digitalWrite(pin, num_array[number][j]);
pin++;
}
}
Here's a video:
1 comment :
Great to see you again! I've read every word on this blog, and after initial excitement became quite sad not seeing any new posts for a while. Good luck with everything! Thank you for Your work! check it out wyze discount code
Post a Comment