Skip to content

Instantly share code, notes, and snippets.

@adamatan
Created July 27, 2012 13:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamatan/3188066 to your computer and use it in GitHub Desktop.
Save adamatan/3188066 to your computer and use it in GitHub Desktop.
Arduino: count from 0 to 255 in Led Binary
/* ---------------------------------------------------------
* | Arduino Experimentation Kit Example Code |
* | CIRC-02 .: 8 LED Fun :. (Multiple LEDs) |
* ---------------------------------------------------------
*
* A few Simple LED animations
*
* For more information on this circuit http://tinyurl.com/d2hrud
*
*/
//LED Pin Variables
int ledPins[] = {2,3,4,5,6,7,8,9}; //An array to hold the pin each LED is connected to
//i.e. LED #0 is connected to pin 2, LED #1, 3 and so on
//to address an array use ledPins[0] this would equal 2
//and ledPins[7] would equal 9
/*
* setup() - this function runs once when you turn your Arduino on
* We the three control pins to outputs
*/
void setup()
{
//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 8; i++){ //this is a loop and will repeat eight times
pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
} //the code this replaces is below
}
void loop() // run over and over again
{
//oneAfterAnotherLoop(); //does the same as oneAfterAnotherNoLoop but with
//much less typing
//oneOnAtATime(); //this will turn one LED on then turn the next one
//on turning the
//former off (one LED will look like it is scrolling
//along the line
//inAndOut(); //lights the two middle LEDs then moves them out then back
//in again
for (int i=0; i<256; i++) {
showBinNumber(i);
delay(256-i);
}
}
void showBinNumber(int num) {
for (int i=0; i<8; i++) {
if (num%2)
digitalWrite(ledPins[i], HIGH);
else
digitalWrite(ledPins[i], LOW);
num/=2;
}
}
@Mtpkp
Copy link

Mtpkp commented Apr 18, 2018

thanks for the code ...but then how can i simulate the code using proteus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment