week 9:output devices
Gert's training
During this week’s training, Gert showed us how to use the oscilloscope to check if the power voltage influences the performance of an output
new iteration
For this week’s assignment, I decided to reuse the PCB board I designed back in Week 5. The reference from Adrián Torres’ Fab Academy documentation turned out to be extremely helpful when planning the pin layout and connections. It seems that the board I designed is well-suited not only for controlling the servo motor I used in weeks 5 and 6, but also for experimenting with various input devices.
Since I am still questioning which kind of detectors would be the best to include in my final project I decided to use a distance detector sensor
#include
Servo myservo;
const int buttonPin = 1;
const int servoPin = 26;
const int ledPin = 0;
int buttonState = 0;
int lastButtonState = LOW;
int servoAngle = 0;
void setup() {
myservo.attach(servoPin);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH); // LED on initially
servoAngle = 0;
myservo.write(servoAngle);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (lastButtonState == LOW && buttonState == HIGH) {
digitalWrite(ledPin, LOW);
// Rotate +90° but wrap back to 0° if beyond 180
servoAngle += 90;
if (servoAngle > 180) {
servoAngle = 0;
}
myservo.write(servoAngle);
delay(400); // debounce delay
digitalWrite(ledPin, HIGH); // LED back on after move
}
lastButtonState = buttonState;
}