Murphy's Law is a funny thing. As someone who whose career revolves around troubleshooting issues in production environments, I've learned quickly that even when dealing with seemingly simple systems, things can and usually will go wrong.
While building my second circuit for my button, I've discovered that my bread board is either damaged or just really cheap. There seems to be an issue with the left/center side of the board where even the slightest pressure on the board causes frantic activation of any GPIO port connected to that part of the board. I discovered this by re-creating my circuit on a different part of the board. This worked without any issue.
Unfortunately, this means I have to wait until the 19th before my new bread board gets here. In positive news, I've been working on the logic for my game! I am incredibly happy with it so far. Again, I've opted in using absolutely no libraries to simulate developing with resource constraints in mind. Cheers to an awesome start!:
//Simon Says for the Arduino R4.
//Input for Buttons.
const int RED_BUTTON_PIN = 5;
const int GREEN_BUTTON_PIN = 4;
//External output for LEDs
const int RED_LED_PIN = 11;
const int GREEN_LED_PIN = 12;
int simonOutput[4];
void setup() {
// initialize output pins
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
// initialize input pins
pinMode(RED_BUTTON_PIN, INPUT);
pinMode(GREEN_BUTTON_PIN, INPUT);
//Initialize Serial Baud rate to 9600
Serial.begin(9600);
}
void loop() {
int i;
for (i = 0; i< 4; i++){
//Find modulo 3 to represent/oputput 3 possible colors.
int randomNum = (analogRead(A0)) % 3;
simonOutput[i] = randomNum;
}
//Print tests to confirm values are, indeed, random!
Serial.println("Simon says: ");
Serial.println(simonOutput[0]);
delay(500);
Serial.println("Simon says: ");
Serial.println(simonOutput[1]);
delay(500);
Serial.println("Simon says: ");
Serial.println(simonOutput[2]);
delay(500);
Serial.println("Simon says: ");
Serial.println(simonOutput[3]);
delay(500);
//Just testing button press logic. Ignore for now.
if (digitalRead(RED_BUTTON_PIN)){
Serial.println("Red button pressed");
digitalWrite(RED_LED_PIN, HIGH);
delay(100);
}
if (digitalRead(GREEN_BUTTON_PIN)){
Serial.println("Green button pressed");
digitalWrite(GREEN_LED_PIN, HIGH);
delay(100);
}
else
{
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
}
}- Eric Byrd
Eric Byrd
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.