Last active
January 16, 2017 18:20
-
-
Save alpha1125/6c440b7e1d5d73b706d0e3288a7229cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Blink | |
Turns on an LED on for one second, then off for one second, repeatedly. | |
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO | |
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to | |
the correct LED pin independent of which board is used. | |
If you want to know what pin the on-board LED is connected to on your Arduino model, check | |
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products | |
This example code is in the public domain. | |
modified 8 May 2014 | |
by Scott Fitzgerald | |
modified 2 Sep 2016 | |
by Arturo Guadalupi | |
modified 8 Sep 2016 | |
by Colby Newman | |
modified 2017-01-06 by Lloyd Leung to be used with the top for pins of an ESP8266 ESP-12e nodeMCU lua dev board. | |
*/ | |
int timer = 2000; // The higher the number, the slower the timing. | |
int ledPins[] = { | |
16, 5, 4, 0 | |
}; // an array of pin numbers to which LEDs are attached | |
int pinCount = 4; | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
Serial.println(); | |
Serial.println(); | |
// the array elements are numbered from 0 to (pinCount - 1). | |
// use a for loop to initialize each pin as an output: | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
pinMode(ledPins[thisPin], OUTPUT); | |
Serial.print("Turned pin "); | |
Serial.print(String(thisPin)); | |
Serial.println(" to an OUTPUT pin"); | |
} | |
Serial.println(); | |
Serial.println(); | |
} | |
void readPin(int thisPin){ | |
Serial.print("Reading pin "); | |
Serial.print(thisPin); | |
if(digitalRead(ledPins[thisPin])){ | |
Serial.println(" HIGH"); | |
}else { | |
Serial.println(" LOW"); | |
} | |
} | |
void onOff(int thisPin) { | |
// turn the pin on: | |
digitalWrite(ledPins[thisPin], HIGH); | |
Serial.print(thisPin); | |
Serial.println("Pin is set HIGH"); | |
delay(timer); | |
readPin(thisPin); | |
// turn the pin off: | |
digitalWrite(ledPins[thisPin], LOW); | |
Serial.print(thisPin); | |
Serial.println("Pin is set LOW"); | |
delay(timer); | |
readPin(thisPin); | |
Serial.println(); | |
Serial.println(); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
// loop from the lowest pin to the highest: | |
for (int thisPin = 0; thisPin < pinCount; thisPin++) { | |
onOff(thisPin); | |
} | |
// loop from the highest pin to the lowest: | |
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { | |
onOff(thisPin); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment