/*Write a program to display the numbers in the increasing and decreasing order from
1 to 15 and vice versa in binary form, using 4 LEDs, with a delay of 1 sec. When it
reaches the maximum value (15), start counting down to 1, then again begin counting
up to 15, then start from 1. Whenever it comes to the Max or Min value, wait for 2 seconds.
*/
const int numLEDs = 4;
const int GPIO_Pins[] = {1, 5, 8, 15};
const int blinkRate = 1000;
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < numLEDs; i++)
pinMode(GPIO_Pins[i], OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//int binary[][4] = {{0,0,0,1},{0,0,1,0},{0,0,1,1},{0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},{1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},{1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}};
int binary[15][4];
for (int i = 0; i < 15; i++)
{
int num = i + 1;
for (int j = 3; j >= 0; j--)
{
int n = num % 2;
num = num / 2;
binary[i][j] = n;
}
}
for(int i = 0; i < 15; i++)
{
for (int j = 0; j < 4; j++)
{
if (binary[i][j] == 1)
{
digitalWrite(GPIO_Pins[j], HIGH);
}
else
{
digitalWrite(GPIO_Pins[j], LOW);
}
}
delay(1000);
}
delay(2000);
for(int i = 14; i >= 0; i--)
{
for (int j = 0; j < 4; j++)
{
if (binary[i][j] == 1)
{
digitalWrite(GPIO_Pins[j], HIGH);
}
else
{
digitalWrite(GPIO_Pins[j], LOW);
}
}
delay(1000);
}
delay(2000);
}