Professional Documents
Culture Documents
Practical Exam
Practical Exam
LED Blink:
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(8, OUTPUT);
}
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
// no need to repeat the melody.
}
Video Link: https://www.youtube.com/watch?v=K8AnlUT0ng0
Knob Circuit
#include <Servo.h>
void setup() {
myservo.attach(8); // attaches the servo on pin 9 to the servo object
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer
(value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it for use with the servo (value
between 0 and 180)
myservo.write(val); // sets the servo position according to
the scaled value
delay(15); // waits for the servo to get there
}
Video Link for knob and sweep: https://www.youtube.com/watch?v=BfQpzlijMkE
Sweep
#include <Servo.h>
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable
'pos'
delay(15); // waits 15 ms for the servo to reach the
position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable
'pos'
delay(15); // waits 15 ms for the servo to reach the
position
}
}
4 pcs. Potentiometer
4 pcs. Pushbutton
4 pcs. LED
Resistors