Well, not exactly HER brain, per-say. However, it is her brain for her science project on the brain. She’s in junior high now (reserve your old-man jokes now), so she has lofty projects from here on out. Cat had to demonstrate ten parts of the brain, so we built it … electronics style.
An Arduino is the main chunk of the brain, running the LEDs, via optocouplers, to allow a low and high side to the circuit. 9v is running the high side, while the low-side is stepped down to 5v by the Arduino. I think, it’s an elegant solution to Emerystein’s Monster!
Gallery and code follow:
#Arduino code const int ONE = 0; const int TWO = 1; const int THREE = 2; const int FOUR = 3; const int FIVE = 4; const int SIX = 5; const int SEVEN = 6; const int EIGHT = 7; const int NINE = 8; const int TEN = 9; const int ELEVEN = 10; const int BUTTON = 11; int countUp = 0; int buttonState = LOW; int pressedButton = 0; long lastDebounceTime = 0; long debounceDelay = 200; const int SYNONE = 50; long blinkOne = 0; const int SYNTWO = 100; long blinkTwo = 0; void setup() { writeLow(); pinMode(ONE, OUTPUT); pinMode(TWO, OUTPUT); pinMode(THREE, OUTPUT); pinMode(FOUR, OUTPUT); pinMode(FIVE, OUTPUT); pinMode(SIX, OUTPUT); pinMode(SEVEN, OUTPUT); pinMode(EIGHT, OUTPUT); pinMode(NINE, OUTPUT); pinMode(TEN, OUTPUT); pinMode(ELEVEN, OUTPUT); pinMode(BUTTON, INPUT); } void loop() { synFire(); if (buttonPressed()) { brainMode(countUp); countUp++; if (countUp >= 12) { countUp = 0; writeLow(); } } } void synFire() { if (countUp == 11) { int randOne = random(ONE, ELEVEN); int randTwo = random(ONE, ELEVEN); unsigned long firstFire = millis(); if ((firstFire - blinkOne) > SYNONE) { blinkOne = firstFire; brainMode(randOne); digitalWrite(ELEVEN, HIGH); } if ((firstFire - blinkTwo) > SYNTWO) { blinkTwo = firstFire; brainMode(randTwo); digitalWrite(ELEVEN, HIGH); } } } boolean buttonPressed() { boolean state = false; buttonState = digitalRead(BUTTON); if (pressedButton == 0) { if ((millis() - lastDebounceTime) > debounceDelay) { if (buttonState == HIGH) { state = true; lastDebounceTime = millis(); pressedButton = 1; } } } if (pressedButton == 1 && buttonState == LOW) { pressedButton = 0; } return state; } void brainMode(int mode) { writeLow(); switch(mode) { case ONE: digitalWrite(ONE, HIGH); digitalWrite(TWO, HIGH); digitalWrite(TEN, HIGH); break; case TWO: digitalWrite(TWO, HIGH); break; case THREE: digitalWrite(THREE, HIGH); break; case FOUR: digitalWrite(FOUR, HIGH); break; case FIVE: digitalWrite(FIVE, HIGH); break; case SIX: digitalWrite(SIX, HIGH); break; case SEVEN: digitalWrite(SEVEN, HIGH); break; case EIGHT: digitalWrite(EIGHT, HIGH); break; case NINE: digitalWrite(NINE, HIGH); break; case TEN: digitalWrite(TEN, HIGH); break; case ELEVEN: digitalWrite(ELEVEN, HIGH); break; } } void writeLow() { digitalWrite(ONE, LOW); digitalWrite(TWO, LOW); digitalWrite(THREE, LOW); digitalWrite(FOUR, LOW); digitalWrite(FIVE, LOW); digitalWrite(SIX, LOW); digitalWrite(SEVEN, LOW); digitalWrite(EIGHT, LOW); digitalWrite(NINE, LOW); digitalWrite(TEN, LOW); digitalWrite(ELEVEN, LOW); }