Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Binary counter sketch
- //1-25-12
- //By: Caleb
- //Only uses 5 LEDs to blink, since I only have 5 220-ohm resistors and five single color LEDs
- //stops at 31 and resets to loop again (otherwise during the loop() method the pins will not change)
- //Written for Arduino uno using the for loop example circuit
- int timer = 100;
- int count = 1;
- void setup(){
- pinMode(2, OUTPUT);//0 or 1
- pinMode(3, OUTPUT);//2
- pinMode(4, OUTPUT);//4
- pinMode(5, OUTPUT);//8
- pinMode(6, OUTPUT);//16
- }
- void loop()
- {
- int rem;
- for(count; count< 31; count++)
- {
- rem = count;
- if(rem>=16)
- {
- digitalWrite(6, HIGH);
- rem = rem-16;
- }else{
- digitalWrite(6, LOW);
- }
- if(rem>=8)
- {
- digitalWrite(5, HIGH);
- rem = rem-8;
- }else{
- digitalWrite(5, LOW);
- }
- if(rem>=4)
- {
- digitalWrite(4, HIGH);
- rem = rem-4;
- }else{
- digitalWrite(4, LOW);
- }
- if(rem>=2)
- {
- digitalWrite(3, HIGH);
- rem = rem-2;
- }else{
- digitalWrite(3, LOW);
- }
- if(rem >=1)
- {
- digitalWrite(2, HIGH);
- rem = rem-1;
- }else{
- digitalWrite(2, LOW);
- }
- delay(timer*4);
- for(int i = 2; i < 7; i++)
- {
- digitalWrite(i, LOW);
- }
- }
- count = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement