I could play with LEDs and Buttons ! I wanted to make cute 3 LED lights. Also, I wanted to try boolean buttons for the LEDs and Buttons. When I push buttons, it stays ON and when I push once again, it turns OFF.
(1) 3 LEDs
int ledPin_red = 11;
int ledPin_yellow = 12;
int ledPin_blue = 13;
I used the example provided by Arduino, and added a couple LEDs. I wanted the LEDs to all turn on and off progressively, instead of taking turns blinking to I changed the order of the HIGH/LOW commands.
For this one, I used the same Arduino set up as I had for the blinking LEDs and just added buttons to the breadboard and connected them to the Arduino. As you will see in the video, one button turns on the red and yellow LEDs and the other button turns on the blue and yellow LEDs.
Blinking LEDs (or Christmas Lights as I have deemed them)
References: I used the built in example and expounded upon it. For both of these, Carl Jadaa showed me that the number of LEDs for any given activity is irrelevant, so I took the attitude of the more, the merrier.
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(led3, LOW); // turn the LED off by making the voltage LOW
delay(200); // wait for a second
}
LED Buttons
References: Used the built in example and expounded.
// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int buttonPin2 = 4;
const int ledPin2 = 12;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin2, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
if (buttonState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin2, LOW);
}
}
I did the very simple version but the review class last week helped. To me, API is more interesting than Canvas, and also more useful, I guess. I would love to learn more and use it in the future.
success : function(parsed_json) { console.log(‘success!!’); //each nested object goes in [] var location = parsed_json[‘current_observation’][‘display_location’][‘full’]; var latitude = parsed_json[‘current_observation’][‘display_location’][‘latitude’]; var longitude = parsed_json[‘current_observation’][‘display_location’][‘longitude’]; var weather = parsed_json[‘current_observation’][‘weather’]; var temper = parsed_json[‘current_observation’][‘temp_c’]; var humidity = parsed_json[‘current_observation’][‘relative_humidity’]; var UV = parsed_json[‘current_observation’][‘UV’];
It was REALLY hard to finish this assignment, however I finally figure out what the API and JSON is. Thanks Master P!! This is not a final version, because I do not have A server. To figure out this assignment Soohyun Park helped me a lot. Following code is what is did.
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>JSON WITH API</title>