As Abraham Lincoln stated "Give me six hours to chop down a tree and I will spend the first four sharpening the axe" we need sharpen our basics
Ex 1 - 5
1.single led
void setup()
{
pinMode(4, OUTPUT);
}
void loop()
{
digitalWrite (4, HIGH);
delay(1000);
digitalWrite (4, LOW);
delay (1000);
}
2.Multiple led
int ledAPin = 2; int ledBPin = 3; void setup() { Serial.begin(9600); pinMode(ledAPin, OUTPUT); pinMode(ledBPin, OUTPUT); Serial.println("Enter 'a' to turn on LED A, 'b' to turn on LED B and 'o' to turn both the LEDs off: "); }
void loop() { // read the sensor: if (Serial.available() > 0) { int led = Serial.read(); switch (led) { case 'a': digitalWrite(ledAPin, HIGH); Serial.println("LED A ON"); break; case 'b': digitalWrite(ledBPin, HIGH); Serial.println("LED B ON"); break; case 'o': //turns of both LEDs digitalWrite(ledAPin, LOW); digitalWrite(ledBPin, LOW); Serial.println("Both the LEDs OFF"); break; default: Serial.println("Invalid Case"); } } }
3.pattern led
long distance; int duration; int trigpin=2; int echopin=3;