For this week’s assignment, I used potentiometer as an analogue sensor, and a tactile button as a digital sensor (switch) and two LEDs. For the LED that is controlled by the tactile button, I made it so that it blinks twice and the potentiometer for brightness control.
Code:
int led = 11;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(8, OUTPUT);
pinMode(A2, INPUT);
}
// the loop function runs over and over again forever
void loop() {
int button1State = digitalRead(A2);
int sensorValue = analogRead(A1);
Serial.println(sensorValue);
analogWrite(led, sensorValue/4);
delay(30);
if (button1State == HIGH) {
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(1000);
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
delay(1000);
} else if (button1State == LOW){
digitalWrite(8, LOW);
}
}
Video:
