/*EX2,2.1:Write a program to display the numbers in increasing order from 1 to 15
in binary form, using 4 LEDs, with a delay of 1 sec. When it reaches the maximum
value (15), wait 2 seconds and start from the minimum (1).*/
const int numLEDs = 4;
static int arr[5];
const int GPIO_Pins[] = {0,1,2,3};
void setup() {
// put your setup code here, to run once:
for (int led = 0; led < numLEDs; led++)
{
pinMode(GPIO_Pins[led], OUTPUT);
digitalWrite(GPIO_Pins[led],LOW);
}
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 1; i <= 15; i++) {
binaryLEDs(i);
delay(1000);
}
delay(2000);
}
void binaryLEDs(int num)
{
for (int i = 0; i < 4; i++) {
arr[i] = num % 2;
num = num / 2;
if (arr[i] == 1)
digitalWrite(GPIO_Pins[i], HIGH);
else
digitalWrite(GPIO_Pins[i], LOW);
}
}