Code for Stupid Pet Trick: Unblocked (Game)
// declare variables:
int switchPin = 2; // digital input pin for a switch
int yellowLedPin = 3; // digital output pin for an LED
int redLedPin = 4; // digital output pin for an LED
int greenLedPin = 6;
int redLed2Pin = 9;int switchState = 0; // the state of the switch
int brightness = 0;
void setup() {
pinMode(switchPin, INPUT); // set the switch pin to be an input
pinMode(yellowLedPin, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLedPin, OUTPUT); // set the red LED pin to be an output
pinMode(greenLedPin, OUTPUT); // set the green LED pin to be an output
pinMode(redLed2Pin, OUTPUT); // set the second redLed pin to be an output
}void loop() {
// read the switch input:
switchState = digitalRead(switchPin);if (switchState == 1) {
// if the switch is closed:
digitalWrite(yellowLedPin, HIGH); // turn on the yellow LED
digitalWrite(redLedPin, LOW); // red LED is off
}
else {
// if the switch is open:
digitalWrite(yellowLedPin, LOW); // turn off the yellow LED
digitalWrite(redLedPin, HIGH); // red pin is on
// turn on the red LED
}brightness = brightness++; //this will set the green LED pin to increase light gradually
delay(200);if(brightness > 255){ //this stops the green LED once it reaches maximum brightness
brightness = 255; //brightness is set to the highest value at 255
digitalWrite(redLed2Pin, HIGH); //here, all of the lights will blink. delay sets the speed.
digitalWrite(redLedPin, HIGH);
digitalWrite(yellowLedPin, HIGH);
delay(300);
digitalWrite(redLed2Pin, LOW);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
delay(300);
}analogWrite(greenLedPin, brightness); //analog write is used because the values for the green LED pin is not digital (on or off only). So, use analogWrite to send values between the board and green Pin.
}