Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Demo the quad alphanumeric display LED backpack kit
- // Counts up and lights up LED when the button is pressed
- // Update: Fixed button and LED not lighting up
- // Update: lastButtonState set to buttonState after updating buttonState
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include "Adafruit_LEDBackpack.h"
- Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
- void setup() {
- pinMode(3, OUTPUT);
- pinMode(7, INPUT_PULLUP);
- alpha4.begin(0x70);
- alpha4.writeDigitRaw(3, 0x0);
- alpha4.writeDigitRaw(0, 0xFFFF);
- alpha4.writeDisplay();
- delay(200);
- alpha4.writeDigitRaw(0, 0x0);
- alpha4.writeDigitRaw(1, 0xFFFF);
- alpha4.writeDisplay();
- delay(200);
- alpha4.writeDigitRaw(1, 0x0);
- alpha4.writeDigitRaw(2, 0xFFFF);
- alpha4.writeDisplay();
- delay(200);
- alpha4.writeDigitRaw(2, 0x0);
- alpha4.writeDigitRaw(3, 0xFFFF);
- alpha4.writeDisplay();
- delay(200);
- alpha4.clear();
- alpha4.writeDisplay();
- }
- int count = 0;
- int buttonState = 0;
- int lastButtonState = LOW;
- void loop() {
- if (buttonState == HIGH and lastButtonState != buttonState) {
- count = count + 1;
- }
- if (count > 9999) {
- count = 0;
- }
- digitalWrite(3, buttonState);
- String countString = String(count);
- lastButtonState = buttonState;
- buttonState = digitalRead(7);
- alpha4.writeDigitAscii(0, countString.charAt(-4 + countString.length()));
- alpha4.writeDigitAscii(1, countString.charAt(-3 + countString.length()));
- alpha4.writeDigitAscii(2, countString.charAt(-2 + countString.length()));
- alpha4.writeDigitAscii(3, countString.charAt(-1 + countString.length()));
- alpha4.writeDisplay();
- alpha4.clear();
- delay(20);
- }
Add Comment
Please, Sign In to add comment