Arduino UNO:
Mạch đèn giao thông:
Code 1 đèn giao thông:
int Red = 13;int Yellow = 12;
int Green = 11;void setup() {
pinMode(Red, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);
}void loop() {
dengiaothong(1, 0, 0);delay(5000);
dengiaothong(0, 0, 1);delay(5000);dengiaothong(0, 1, 0);delay(2000);
}void dengiaothong(int R, int Y, int G) {
digitalWrite(Red, R);
digitalWrite(Yellow, Y);
digitalWrite(Green, G);
}
Code 2 đèn giao thông:
int Red = 13;int Yellow = 12;
int Green = 11;int Red2 = 10;int Yellow2 = 9;
int Green2 = 8;void setup() {
pinMode(Red, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);pinMode(Red2, OUTPUT);
pinMode(Yellow2, OUTPUT);
pinMode(Green2, OUTPUT);
}void loop() {dengiaothong(1, 0, 0);dengiaothong2(0, 0, 1);delay(5000);dengiaothong(1, 0, 0);dengiaothong2(0, 1, 0);delay(2000);dengiaothong(0, 0, 1);dengiaothong2(1, 0, 0);delay(5000);}dengiaothong(0, 1, 0);dengiaothong2(1, 0, 0);delay(2000);void dengiaothong(int R, int Y, int G) {
digitalWrite(Red, R);
digitalWrite(Yellow, Y);
digitalWrite(Green, G);
}void dengiaothong2(int R, int Y, int G) {
digitalWrite(Red2, R);
digitalWrite(Yellow2, Y);
digitalWrite(Green2, G);
}