Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte BUTTON = 2;
- const byte LED_START = 3;
- const byte LEDS = 4;
- boolean autoMode = true;
- const int autoDelay = 500;
- byte val = 0;
- int buttonState = false;
- int lastButton = false;
- void setup()
- {
- Serial.begin(9600);
- pinMode(BUTTON, INPUT);
- for (byte i = 0; i < LEDS; ++i)
- pinMode(LED_START + i, OUTPUT);
- }
- void loop()
- {
- buttonState = digitalRead(BUTTON);
- if ((buttonState != lastButton) || autoMode)
- {
- if ((buttonState == HIGH) || autoMode)
- {
- if (autoMode)
- delay(autoDelay);
- Serial.print("Button press: ");
- Serial.print("val = ");
- Serial.println((int)val);
- val += 1;
- Serial.println(pow(2, LEDS));
- val %= (byte)(pow(2, LEDS));
- }
- }
- lastButton = buttonState;
- for (byte i = 0; i < LEDS; ++i)
- {
- Serial.print("LED");
- Serial.print((int)i);
- Serial.print(" = ");
- Serial.println(bitRead(val, i));
- digitalWrite(LED_START + i, bitRead(val, i));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement