Electricity
digital in digital read
digital out digital rite
GPIO general purpose input output
right to rows of the breadboard
Neo Pixel
**Digital Input In Class Exercise
light two LEDs up**
#define grLEDPin 4
#define redLEDPin 3
#define switchPin 2
int delayAmount = 10;
void setup() {
// put your setup code here, to run once:
pinMode(grLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(switchPin,INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println("Hello");
Serial.println(delayAmount);
Serial.println(millis());
delayAmount++;
if (delayAmount>100){
delayAmount=1;
}
// put your main code here, to run repeatedly:
digitalWrite(grLEDPin,HIGH);
digitalWrite(redLEDPin,LOW);
delay(delayAmount);
digitalWrite(grLEDPin,LOW);
digitalWrite(redLEDPin,HIGH);
delay(delayAmount);
digitalWrite(grLEDPin,LOW);
digitalWrite(redLEDPin,LOW);
delay(delayAmount);
}
Use Switch to turn LEDs on
#define grLEDPin 4
#define redLEDPin 3
#define switchPin 2
int delayAmount = 10;
void setup() {
// put your setup code here, to run once:
pinMode(grLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(switchPin,INPUT);
Serial.begin(9600);
}
void loop() {
int switchState = digitalRead(switchPin);
Serial.println(switchState);
if (switchState==HIGH){
digitalWrite(grLEDPin,HIGH);
digitalWrite(redLEDPin,LOW);
delay(delayAmount);
digitalWrite(grLEDPin,LOW);
digitalWrite(redLEDPin,HIGH);
delay(delayAmount);
}
else{
digitalWrite(grLEDPin,LOW);
digitalWrite(redLEDPin,LOW);
delay(delayAmount);
}
}
Or
#define grLEDPin 4
#define redLEDPin 3
#define switchPin 2
int delayAmount = 10;
void setup() {
// put your setup code here, to run once:
pinMode(grLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(switchPin,INPUT);
Serial.begin(9600);
}
void loop() {
int switchState = digitalRead(switchPin);
digitalWrite(grLEDPin, ! switchPin);
Serial.println(switchState);
}
Q
bool
int
The Arduino boards have a few pins which can generate a continuous PWM signal. On the Arduino Nano 33 IoT. they’re pins 2, 3, 5, 6, 9, 10, 11, 12, A2, A3, and A5. On the Arduino Uno, they’re pins 3, 5, 6, 9, 10, and 11. To control them, you use the analogWrite() command like so: