Lesson 2: More LEDs
עמוד זה דורש דפדפן עדכני (תומך ב-SharedArrayBuffer). אנא עדכן את Chrome, Edge, Firefox או Safari לגרסה העדכנית ביותר.
English
One pin for each LED
- Each LED needs its own pin and its own
pinMode. - In a real circuit each LED also needs a resistor (about 220 Ω), so it does not burn out.
void setup() {
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
delay(500);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(500);
}
- Press Run: the two LEDs take turns.
- The board is very fast. Two
digitalWritelines with nodelaybetween them happen at (almost) the same time.
English
A traffic light
| Step | Red (10) | Amber (9) | Green (8) | Time |
|---|---|---|---|---|
| 1 | on | off | off | 2 s |
| 2 | on | on | off | 1 s |
| 3 | off | off | on | 2 s |
| 4 | off | on | off | 1 s |
- Then it starts again at step 1. This is the order in the UK.
רמת קושי 1/5 · 100 מטבעות + בונוס קטן בהשלמה הראשונה היום
Pins 2 (blue) and 3 (red) take turns: pin 2 on and pin 3 off for 300 ms, then pin 2 off and pin 3 on for 300 ms, again and again.
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
Make the traffic light from the table: red on pin 10, amber on pin 9, green on pin 8. Steps of 2 s, 1 s, 2 s, 1 s, then again.
לחץ על הרץ כדי לראות את התוצא כאן.