For this week’s assignment, I wanted to incorporate the counting ability of the Arduino and the LED.
The concept was that when the button is pressed a certain amount of times, the monitor would display annoyance: “bruh stop pressing me” and ” is this fun?” are just a few of the phrases the monitor will give back to the user.
Then, after a certain number of times the button has been pushed, red LED will light up, indicating that Arduino is r e a l l y mad at the user.
Although I got the computer to say phrases in the monitor depending on the amount of times the button has been pushed, when I tried to run the code for turning on the Red LED, the USB ports on my laptop suddenly started to not work. After multiple attempts of unplugging and plugging for an hour, I decided to try again tomorrow morning and hope that my code for the LED is correct. This paragraph is in Comic Sans because my life is a joke at this point
For future developments, I want to incorporate using arrays and random function so that the computer can generate random statements from the possible sayings in the array. I would also like to have a green LED that would be on until the user has pressed the button enough. When the user reaches the limit, the green LED would go off, and the red LED would turn on.
also, I’m not sure why the photo qualities are so bad — even the screen screen capture ones. Here is the code that I did:
int lastButtonState = LOW; // state of the button last time you checked
int buttonPresses = 0;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// make pin 2 an input:
pinMode(2, INPUT);
pinMode (3, OUTPUT);
}
void loop() {
// read the pushbutton:
int buttonState = digitalRead(2);
int led = digitalRead (3);
// if it’s changed and it’s high, toggle the mouse state:
if (buttonState != lastButtonState) {
if (buttonState == HIGH && buttonPresses <30) {
buttonPresses ++;
Serial.println(“Button was just pressed.”);
Serial.print (buttonPresses);
Serial.println (“times.”);
}
if (buttonPresses > 10 && buttonPresses <30) {
Serial.println (“bruh stop pressing me”);
} if (buttonPresses >15 && buttonPresses <30) {
Serial.println (“is this fun?” );
} if (buttonPresses > 20 && buttonPresses <30) {
Serial.println (“go work on your homework” );
} if (buttonPresses == 25&& buttonPresses <30) {
digitalWrite (3, HIGH);
delay (100);
digitalWrite (3,LOW);
delay (100);
digitalWrite (3, HIGH);
} if (buttonPresses == 30) {
Serial.println (“goodbye”);
}
else {
digitalWrite (3, LOW);
}
}
// save button state for next comparison:
lastButtonState = buttonState;
}
update: it’s the morning and the laptop still can’t read my usb port 🙁
second update: after resetting my Arduino by pressing the reset button twice (thank you Yeseul), my computer was able to read the port again.
However, my LED was not working, and with my intuition I got the led pins out and saw that the long leg was connected to ground. After changing it, it worked yay! Here is a video: