Week 2 : Microcontroller Circuits
Sept 18, 2022
Week2: Inputs + Sensors
* I had issues uploading the code to the board. My laptop kept changing the port every single time I tried to connect and upload codes to my board. I brought it up to the pComp lab but nobody knew what’s wrong...

-> solved * installed the driver again and it’s working... maybe mine was outdated? (previous one was installed 2 weeks ago..)
Digital Input (pushbutton) and Digital Output (LED)


* always need to check the LED’s longer side and shorter side....
Analog Input (pushbutton) and Analog Output (LED)
**code** for led
const int ledPin = 9;
int analogValue = 0;
int brightness = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(ledPin, OUTPUT);
}
**code** for led
const int ledPin = 9;
int analogValue = 0;
int brightness = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
analogValue = analogRead(A0);
brightness = analogValue /4; /
analogWrite(ledPin, brightness);
Serial.println(brightness);
}



*tried to replace the LED with a speaker
-> sounds 3 different tones
with these codes
void loop() {
analogValue = analogRead(A0);
frequency = (analogValue /4) * 10;
tone(A0, frequency);
Serial.println(frequency);
}
Analog Input (Force Sensing Resistor) / Digital Input(pushButton) and Output (println)


issue!
if (buttonState == HIGH) {buttonPresses++;
Serial.print target="_blank">Serial.print("Button has been pressed ");
Serial.print(buttonPresses);
Serial.println(" times.");
}
-> it should be ++ when i press the button
-> it does but in a weird way...
-> maybe it’s counting the frames as well?