Skip to content

Instantly share code, notes, and snippets.

@mbrav
Last active August 10, 2016 07:39
Show Gist options
  • Save mbrav/eb513093316393b7623b to your computer and use it in GitHub Desktop.
Save mbrav/eb513093316393b7623b to your computer and use it in GitHub Desktop.
/*
Artificial Personality Box
Created 3 May 2015
by Michael Braverman
*/
int whiteLED = 10;
int redLED = 12;
int greenLED = 9;
int yellowLED = 11;
int buttonPin = 13;
unsigned long previousMillisRed = 0;
unsigned long previousMillisYellow = 0;
unsigned long previousMillisWhite = 0;
void setup() {
Serial.begin(115200);
pinMode(whiteLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
// Unless the button was pressed, do not start the loop program
}
void loop() {
// MAIN SPEECH
if (timeFrame(-15000, 6000)) {
randomBlink(250);
}
if (timeFrame(6000, 7500)) {
randomBlink(10);
}
if (timeFrame(8800, 10000)) {
randomBlink(30);
}
if (timeFrame(11000, 14500)) {
randomBlink(20);
}
if (timeFrame(16200, 20000)) {
randomBlink(20);
}
if (timeFrame(22000, 23100)) {
randomBlink(10);
}
if (timeFrame(24000, 28000)) {
randomBlink(10);
}
if (timeFrame(29000, 30000)) {
randomBlink(20);
}
if (timeFrame(30300, 31100)) {
randomBlink(20);
}
if (timeFrame(31500, 35200)) {
randomBlink(30);
}
if (timeFrame(36500, 38000)) {
randomBlink(20);
}
if (timeFrame(39000, 39900)) {
randomBlink(10);
}
if (timeFrame(40400, 41000)) {
randomBlink(10);
}
if (timeFrame(41000, 43400)) {
randomBlink(50);
}
if (timeFrame(44200, 45400)) {
randomBlink(10);
}
if (timeFrame(49000, 49500)) {
randomBlink(20);
}
if (timeFrame(50000, 54400)) {
randomBlink(10);
}
if (timeFrame(56200, 57300)) {
randomBlink(10);
}
if (timeFrame(57500, 62000)) {
randomBlink(30);
}
if (timeFrame(64080, 65900)) {
randomBlink(20);
}
if (timeFrame(66000, 67700)) {
randomBlink(10);
}
if (timeFrame(68000, 71500)) {
randomBlink(30);
}
if (timeFrame(72400, 74500)) {
randomBlink(20);
}
if (timeFrame(75000, 77500)) {
randomBlink(10);
}
if (timeFrame(79300, 81700)) {
randomBlink(20);
}
if (timeFrame(82000, 84000)) {
randomBlink(10);
}
if (timeFrame(84400, 86600)) {
randomBlink(10);
}
if (timeFrame(87600, 93600)) {
randomBlink(20);
}
if (timeFrame(94700, 97400)) {
randomBlink(20);
}
if (timeFrame(98600, 104500)) {
randomBlink(30);
}
if (timeFrame(106400, 113400)) {
randomBlink(10);
}
if (timeFrame(114600, 115500)) {
randomBlink(10);
}
if (timeFrame(116000, 118300)) {
randomBlink(10);
}
if (timeFrame(120500, 122500)) {
randomBlink(10);
}
if (timeFrame(124400, 125200)) {
randomBlink(10);
}
if (timeFrame(128400, 136400)) {
randomBlink(10);
}
if (timeFrame(137600, 140700)) {
randomBlink(30);
}
if (timeFrame(142200, 145000)) {
randomBlink(10);
}
if (timeFrame(145700, 148500)) {
randomBlink(10);
}
if (timeFrame(149400, 152000)) {
randomBlink(10);
}
if (timeFrame(149400, 152000)) {
randomBlink(10);
}
// ECHO SPEECH
if (timeFrame(153700, 158400)) {
randomBlink(20);
}
if (timeFrame(160300, 164700)) {
randomBlink(30);
}
if (timeFrame(166300, 170700)) {
randomBlink(10);
}
if (timeFrame(171000, 207000)) {
randomBlink(250);
}
// digitalWrite(whiteLED, HIGH);
// delay(500);
// digitalWrite(redLED, HIGH);
// delay(500);
// digitalWrite(greenLED, HIGH);
// delay(500);
// digitalWrite(yellowLED, HIGH);
// delay(500);
// digitalWrite(whiteLED, LOW);
// digitalWrite(redLED, LOW);
// digitalWrite(greenLED, LOW);
// digitalWrite(yellowLED, LOW);
// delay(500);
// digitalWrite(whiteLED, HIGH);
// digitalWrite(redLED, HIGH);
// digitalWrite(greenLED, HIGH);
// digitalWrite(yellowLED, HIGH);
// delay(500);
// digitalWrite(whiteLED, LOW);
// digitalWrite(redLED, LOW);
// digitalWrite(greenLED, LOW);
// digitalWrite(yellowLED, LOW);
// delay(500);
// for (byte fadeValue = 0 ; fadeValue <= 255; fadeValue += 1) {
// analogWrite(whiteLED, fadeValue);
// analogWrite(yellowLED, map(fadeValue, 0, 255, 255, 0));
// analogWrite(greenLED, map(fadeValue, 0, 255, 255, 0));
// delay(10);
// }
// for (byte i = 0; i <= 50; i += 1) {
// allOFF();
// delay(50);
// allON();
// delay(50);
// }
}
void allON() {
digitalWrite(whiteLED, HIGH);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, HIGH);
digitalWrite(yellowLED, HIGH);
}
void allOFF() {
digitalWrite(whiteLED, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
}
boolean timeFrame(long beginingMillis, long endMillis) {
if((beginingMillis + 16000) < millis() && (endMillis + 16000) > millis() ) {
return true;
} else {
return false;
}
}
void randomBlink(int blinkDelay) {
byte rand = random(255);
digitalWrite (whiteLED, bitRead(rand, 1));
digitalWrite (redLED, bitRead(rand, 2));
digitalWrite (greenLED, bitRead(rand, 3));
digitalWrite (yellowLED, bitRead(rand, 4));
delay(blinkDelay);
allOFF();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment