-----------------------------------------------
Basic structure of arduino code
-----------------------------------------------
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
---------------------------------------------
//Arduino program to read the input and print it.
void setup()
{
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
int valueread = analogRead(A0);
// print out the value you read:
Serial.println(valueread);
delay(10);
}
---------------------------------------------
//Arduino program to blink the LEDs
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH); // turn the LED on
delay(1000);
digitalWrite(LED, LOW); // turn the LED off
delay(1000);
}
---------------------------------------------
// Reading push button state. digital pin 5 has a
pushbutton
int pushButton = 5;
void setup() {
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1);
}
--------------------------------------------------
//Read pushbutton to glow led
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// 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);
}
}