I’ve been training IT people for over 20 years.
I like to try to introduce school interns to computer science with programming that they have developed themselves.
You will learn the basics of controlling LEDs.
They have to work out the rest themselves and be able to explain it later.
From 2023, they will be able to switch 😡 off the brain completely
Here is the second example on the topic of AI
My input:
Show me a program for traffic light control on an Arduino
Output within 5 seconds
==========
Here’s an example of a traffic light control program on an Arduino:
const int redPin = 9;
const int yellowPin = 10;
const int greenPin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
Red on
digitalWrite(redPin, HIGH);
delay(3000);
Red off, yellow on
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(1000);
Yellow off, green on
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, HIGH);
delay(3000);
Green off, yellow on
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(1000);
Yellow off, red on
digitalWrite(yellowPin, LOW);
digitalWrite(redPin, HIGH);
delay(3000);
}
The program defines the pins to which the traffic lights are connected (red, yellow, green) and sets them as outputs.
In the loop() function, traffic light control is then performed by toggling the respective pins on and off for the colors, using the delay() function to control the duration of each color.
It should be noted that this is only a sample program and there may be different customizations depending on your needs and setup.
==========
No responses yet