CODE PART 2 & 3/4
The code below utilizes arrays and Boolean logic to output an appropriate value, according to my birthday. Below shows the code that can be used with the Arduino to create the correct output:
Part 2: Code:
Part 3/4: Code:
byte num_array[11][7] = { { 1,1,1,1,1,1,0 },
{ 0,1,1,0,0,0,0 },
{ 1,1,0,1,1,0,1 },
{ 1,1,1,1,0,0,1 },
{ 0,1,1,0,0,1,1 },
{ 1,0,1,1,0,1,1 },
{ 1,0,1,1,1,1,1 },
{ 1,1,1,0,0,0,0 },
{ 1,1,1,1,1,1,1 },
{ 1,1,1,0,0,1,1 },
{ 0,0,0,0,0,0,1 }
};
void setup()
{
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}
void loop()
{
Num_Write(0);
delay(2000);
Num_Write(7);
delay(4000);
Num_Write(10);
delay(4000);
Num_Write(1);
delay(2000);
Num_Write(9);
delay(4000);
Num_Write(10);
delay(4000);
Num_Write(0);
delay(2000);
Num_Write(7);
delay(5000);
}
void Num_Write(int number)
{
int pin= 5;
for (int j=0; j < 7; j++)
{
digitalWrite(pin, num_array[number][j]);
pin++;
}
}
​
Click here to see the files:
int x;
int y;
int z;
byte array[5][7] =
{
{ 1,1,1,1,1,1,0 },
{ 0,1,1,0,0,0,0 },
{ 1,1,1,0,0,0,0 },
{ 1,1,1,0,0,1,1 },
{ 0,0,0,0,0,0,1 }
};
void setup()
{
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}
void loop()
{
x = digitalRead(4);
y = digitalRead(3);
z = digitalRead(2);
if (x == LOW && y == LOW && z == LOW)
{
display(0);
}
if (x == LOW && y == LOW && z == HIGH)
{
display(2);
}
if (x == LOW && y == HIGH && z == LOW)
{
display(4);
}
if (x == LOW && y == HIGH && z == HIGH)
{
display(1);
}
if (x == HIGH && y == LOW && z == LOW)
{
display(3);
}
if (x == HIGH && y == LOW && z == HIGH)
{
display(4);
}
if (x == HIGH && y == HIGH && z == LOW)
{
display(0);
}
if (x == HIGH && y == HIGH && z == HIGH)
{
display(2);
}
}
void display(int num)
{
int pin= 5;
for (int j=0; j < 7; j++)
{
digitalWrite(pin, array[num][j]);
pin++;
}
}
​
Click here to see the files:
void setup() {
pinMode(4,INPUT);
pinMode(3,INPUT);
pinMode(2,INPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}
void loop() {
bool x = digitalRead(4);
bool y = digitalRead(3);
bool z = digitalRead(2);
if ((x && !y) || (y && x) || (!y && !z) digitalWrite(5, 1);
else digitalWrite(5, 0);
if ((!x && z) || (!y && !x) || (x && y) || (x && !z)) digitalWrite(6, 1);
else digitalWrite(6, 0);
if ((!x && z) || (!y && !x) || (x && y) || (x && !z)) digitalWrite(7, 1);
else digitalWrite(7, 0);
if ((!x && !z && !y) || (y && x && !z)) digitalWrite(8, 1);
else digitalWrite(8, 0);
if ((!x && !z && !y) || (y && x && !z)) digitalWrite(9, 1);
else digitalWrite(9, 0);
if ((!z && x) || (!z && !y)) digitalWrite(10, 1);
else digitalWrite(10, 0);
if ((!y && x) || (!x && y && !z)) digitalWrite(11, 1);
else digitalWrite(11, 0);
}
​
Click here to see the files: