Skip to content

Instantly share code, notes, and snippets.

@polluxlabs
Created April 18, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polluxlabs/c384893e4f537e8cb6cc1b31087079b9 to your computer and use it in GitHub Desktop.
Save polluxlabs/c384893e4f537e8cb6cc1b31087079b9 to your computer and use it in GitHub Desktop.
/*
pollux labs, 2020
*/
#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int noisePin = 7;
boolean noise = false;
int quote = 0;
byte x = 3;
char *estragonStrings[] = {"PUT",
"YOUR",
"QUOTES",
"HERE"
};
void setup() {
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
pinMode(noisePin, INPUT);
lcd.begin(16, 2);
}
void loop() {
noise = digitalRead(noisePin);
if (noise && x % 2 == 0) { // && x%2 == 0 is even / odd for the other Arduino
quote = random(66); //number is depending on how many quotes you have!
switch (quote) {
case 0: //fill in more cases depending on your number of quotes
displayText(quote);
break;
case 1:
displayText(quote);
break;
case 2:
displayText(quote);
break;
case 3:
displayText(quote);
break;
case 4:
displayText(quote);
break;
}
} else if (!noise) {
lcd.clear();
}
}
void sendByte() {
x++;
Wire.beginTransmission(8);
//Wire.write("x is ");
Wire.write(x);
Wire.endTransmission();
}
void receiveEvent(int howMany) {
while (1 < Wire.available()) {
int c = Wire.read();
Serial.print(c);
}
x = Wire.read();
Serial.println(x);
}
void displayText(int noText) {
lcd.setCursor(0, 1);
delay(1000);
if (strlen(estragonStrings[noText]) > 16) {
lcd.print(estragonStrings[noText]);
delay(1000);
for (int positionCounter = 0; positionCounter < strlen(estragonStrings[noText] + 16); positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(350);
}
} else {
lcd.print(estragonStrings[noText]);
}
delay(3000);
lcd.clear();
sendByte();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment