Basics done, thanks for the patience this far.
I made the blinky light. Yay for me. I made a motor turn and a piezo speaker go on and off when I shone a flashlight on a sensor. What I am working on now is why they do such things. So, I decided to branch out. I can make one led blink, how about more than one? How do I tell my Arduino that there are three leds to blink on and off instead of one? There are code examples that I can plug in and upload in moments, but that wont get me to the root of why.
So, here is a picture of my current setup and the sketch that I thought should work. All i get in one single blinking led (red). Now, I can simply wire the three leds out of one pin, but I'm trying to understand the software/code/sketch aspect of this issue.
Also, under the setup function, I thought that I needed to tell it to intialize three pins as output so I told it start at zero and go until i<2 so that 0, 1, 2, got setup. That resulted in a dimly lit red led. However, when I copied a different example and wound up with i<3 the red led goes back up to full strength.
12 - 1
Code: Select all
int ledPins[] = {4,7,9};
void setup() {
for(int i = 0; i < 3; i++){
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
digitalWrite(ledPins[0,1,2], HIGH);
delay(250);
digitalWrite(ledPins[0,1,2], LOW);
delay(250);
}