Blink a digit in Binary
Hookup for Blink a digit in Binary |
--------------------------- Copy Code Below
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
blinkBin(11); // Call the function to convert a number to binary
}
void blinkBin(int digit) //function creation. The function is created outside setup and loop
{
for(int n = 0; n < 4; n++)
{
if (bitRead(digit,n) == 1) //Long blink for 1 //Use the bitRead function to read each bit of a number
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
else //Short blink for 0
{
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(500);
}
}
delay(3000);
}
No comments:
Post a Comment