Last active
October 23, 2019 14:38
-
-
Save iley/9dab669023c205da6085ba454b51eb4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
#include <Wire.h> | |
const int speakerPin = 9; | |
const int lampPin = 8; | |
const int controlButtons = 3; | |
const int controlButtonPins[] = { 12, 13, 11 }; | |
const int playerButtons = 6; | |
const int playerButtonPins[] = { 5, 4, 3, 2, 1, 0 }; | |
LiquidCrystal lcd(7, 6, A0, A1, A2, A3); | |
void setup() { | |
Wire.begin(); | |
pinMode(speakerPin, OUTPUT); | |
lcd.begin(20, 4); | |
lcd.write("Hello world!"); | |
pinMode(lampPin, OUTPUT); | |
for (int i = 0; i < playerButtons; i++) { | |
pinMode(playerButtonPins[i], INPUT_PULLUP); | |
} | |
for (int i = 0; i < controlButtons; i++) { | |
pinMode(controlButtonPins[i], INPUT_PULLUP); | |
} | |
} | |
void flash() { | |
tone(speakerPin, 2000); | |
digitalWrite(lampPin, HIGH); | |
ExpanderWrite(0x20, 0xff); | |
delay(1000); | |
noTone(speakerPin); | |
digitalWrite(lampPin, LOW); | |
ExpanderWrite(0x20, 0x00); | |
} | |
void loop() { | |
while (true) { | |
for (int i = 0; i < playerButtons; i++) { | |
if (digitalRead(playerButtonPins[i]) == LOW) { | |
lcd.setCursor(0, 1); | |
lcd.write("PLR "); | |
lcd.write('0' + i); | |
flash(); | |
} | |
} | |
for (int i = 0; i < controlButtons; i++) { | |
if (digitalRead(controlButtonPins[i]) == LOW) { | |
lcd.setCursor(0, 1); | |
lcd.write("CTL "); | |
lcd.write('0' + i); | |
flash(); | |
} | |
} | |
} | |
} | |
void ExpanderWrite(byte address, byte value) { | |
Wire.beginTransmission(address); | |
Wire.write(value); | |
Wire.endTransmission(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment