Monday, March 6, 2017

My Arduino Game
     "Stop that LED!"
Description of My Game
The object of my game is to stop the light on the blue LED. To play, press down on button and watch the lights go back and forth. Release your finger off of the button when you think the LED will stop on the blue. If it lands on any other LED but the blue, your score will be subtracted 10 points. If it lands on the blue LED, your score will be added 10 more points. Keep playing to get your score up to 50. It's very hard and will take a while, but it's fun when you have nothing to do!
Example of light not on the blue LED. This means the player will have 10 points subtracted from their score.
Example of light on the blue LED. This means the player will have 10 points added to their score. 

CODE
int ledpin = 13; //starts here
int ledpin2 = 12;
int ledpin3 = 11;
int ledpin4 = 10;
int ledpin5 = 9; //variables for when button is released, stops at this pin^for all of the above
int buttonPin = 2; //see if button is pressed
int buttonState = 0; //
int counter = 0; //count button (score)
int ledpinall = (9, 10, 11, 12, 13);
int count = 0; //declared variables ^

void setup() { //runs once
  Serial.begin(9600); //set up serial library at 9600 bps
  pinMode(buttonPin, INPUT); //initialize as input

} //WHEN BUTTON IS RELEASED, TRY TO LIGHT UP BLUE LED

void loop() { //runs over and over again
    buttonState = digitalRead(buttonPin); //check to see if button is pressed here
    if (buttonState == LOW)
    {
      Serial.println("Press button, then release and try to light up the blue LED!"); //prints "Button Released" on Serial Monitor
      {
        pinMode(ledpin, INPUT); //initialize ledpin as input
        digitalWrite(ledpin, LOW); //turn led off
        }
        if (ledpin!=10) //if ledpin does not land on 10, you lose
        {
          Serial.println ("Loser!"); //print "Loser!" when you do not land on 10
        }
        if (ledpin==10) //if ledpin does land on ten, you win
        {
          Serial.println("Winner!"); //print "Winner!" when you do land on 10
        }
        if (ledpin == 13) //if led pin is 13, then stay on after button is released, same for 4 statements below
        {
          pinMode(ledpin, OUTPUT); //initialize as output
          digitalWrite(ledpin, HIGH);  //turn ledpin 13 on    
        }
        if (ledpin2 == 12) //if ledpin is 12, stay on
        {
          pinMode(ledpin, OUTPUT); //initialize as output
          digitalWrite(ledpin, HIGH);      //turn ledpin 12 on
        }
        if (ledpin3 == 11) //if ledpin is 11, stay on
        {
          pinMode(ledpin, OUTPUT); //initialize as output
          digitalWrite(ledpin, HIGH);    //turn ledpin11 on    
        }
        if (ledpin4 == 10) //if ledpin is 10, stay on after button is released
        {
          pinMode(ledpin, OUTPUT); //initialize as output
          digitalWrite(ledpin, HIGH); //turn ledpin10 on      
        }
        if (ledpin5 == 9) //if ledpin is 9, stay on after button is released
        {
          pinMode(ledpin, OUTPUT); //initialize as output
          digitalWrite(ledpin, HIGH); //turn ledpin9 on
        }
        delay(1000); //wait
    buttonState=digitalRead(buttonPin); //check to see if button is pressed here
    if (ledpin==10 && buttonState==HIGH) //if led pin is 10 and is on, then...
    {
      count=count+10; //add 10 to the score if you land on 10 (blue LED)
      Serial.print("Score="); //writes "Score=" to player's score
      Serial.println(count);
    }
    buttonState=digitalRead(buttonPin); //check to see if button is pressed here
    if (ledpin!=10 && buttonState==HIGH) //if led pin is anything but 10 and is on, then...
    {
      count=count-10; //subtract 1 from the score if you land on anything but 10
      Serial.print("Score="); //writes "score=" to player's score
      Serial.println(count);
    }
 
 
  delay(100); //delay for 100 ms
  buttonState = digitalRead(buttonPin); //check to see if button is pressed here
  if (buttonState == HIGH)
  { //starting of if statement
    Serial.println("Release button when you think your blue LED will light up!"); //prints button pressed with ending line break
    buttonState = digitalRead(buttonPin);
    while (ledpin >9 && buttonState == HIGH) //while led pin is greater than 9, and button is on, then...
   
    {
   
       buttonState = digitalRead(buttonPin);
      pinMode (ledpin, OUTPUT); //initialize as output
      digitalWrite(ledpin, HIGH); //turn led on  
      delay(100); //wait 100 ms
      digitalWrite(ledpin, LOW); //turn led off
      ledpin=ledpin-1; //subtract one from 9 to go down line
    } //end of if statement
  {
    Serial.println("Waiting"); //prints waiting to serial monitor
 
    while (ledpin <13 && buttonState == HIGH) //while ledpin is less than 13, and button is on, then...

    {
     buttonState = digitalRead(buttonPin);
     
      pinMode (ledpin, OUTPUT); //initialize as output
      digitalWrite(ledpin, HIGH); //turn led on
      delay(100); //wait 100 ms
      digitalWrite(ledpin, LOW); //turn led off
      ledpin=ledpin+1; //add to 13
    }
  }
//delay(1000);
  }
}

URL to Video
https://www.youtube.com/watch?v=sJk36eqXYGU&feature=youtu.be



Tuesday, February 28, 2017

Interesting Push Button
   My "Interesting Push Button" causes the LEDs to light up from one end to the other. As the electricity conducts through the scissors, wire cutter, and screw driver, the lights start at LED 13 and goes to LED 9. Then they start at LED 9 again and back to LED 13. Only one light is lit at one time. Once the wire is lifted off of the screw driver, the sequence stops. It starts all over again once the wire is placed back on the screw driver. Every time the LED 13 lights up, the light on the RedBoard, 13, will light up.

CODE
int ledpin = 9;
int buttonPin = 2;
int buttonState = 0;
void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);

}

void loop() {
  delay(100);
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    Serial.println("Button Pressed");
    while (ledpin >=9)
    {
      pinMode (ledpin, OUTPUT);
      digitalWrite(ledpin, HIGH);
      delay(100);
      digitalWrite(ledpin, LOW);
      ledpin=ledpin-1;
    }
  {
    Serial.println("Waiting");
    while (ledpin <= 13)
    {
     pinMode (ledpin, OUTPUT);
     digitalWrite(ledpin, HIGH);
     delay(100);
      digitalWrite(ledpin, LOW);
      ledpin=ledpin+1;
    }
  }
  ledpin = 9;
  ledpin = 13;
  }
}

URL to Video
https://www.youtube.com/watch?v=3bdYIU7NU1o&feature=youtu.be

Tuesday, January 17, 2017

Arduino Projects



     The Word Clock
     The first Arduino Project I thought was extremely cool was "The Word Clock". One day, a husband wanted to give his wife a beautiful gift. Knowing she was an English teacher, he thought it would be unique to make her a word clock. This clock is all words instead of numbers, and the lights go to the correct words that correlate with the time. I think this clock is extremely cool because it has the power to tell the time in many different ways. For example, instead of saying 9:35, the clock says, "It's twenty five minutes to ten." I can't imagine how he got this to work, but it's one of the coolest things I have ever seen.

Link: http://www.instructables.com/id/The-Word-Clock-Arduino-version/

Addressable Milk Bottles (LED Lighting + Arduino)
     The second Arduino project I found interesting was the addressable milk bottles. Used PPE milk bottles can be used as LED lights and are environmentally friendly. This helps with reusing milk bottles and uses less than 3 watts, but still bright enough to see by. I think this is a cool project because along with helping the environment, it's also very aesthetically pleasing. The light glow it gives is very calming and peaceful. It's a beautiful and useful way to reuse a simple product like a milk bottle.

Link: http://www.instructables.com/id/Milk-Bottle-LED-Lights-Arduino-Controlled/