Week3 Analog Output
Lab1 Digital Input and Output
A force sensor controlling the frequency of the sound. The problem was that the sound is very low since it’s a big speaker. So I connected the speaker to an independent 5V power and added a MOSFET to control it. The final result is showing below. It was extremely loud.
const int speaker = 2;
const int input = A0;
void setup() {
pinMode(input, INPUT);
}
void loop() {
int value = analogRead(input);
float frequency = map(value, 0, 1023, 100, 1000);
tone(speaker, frequency);
delay(10);
}
Lab2 Servo motor control
The Servo.h module is very easy to use.
#include <Servo.h>
Servo theServo;
void setup() {
theServo.attach(2);
}
void loop() {
int value = analogRead(A0);
int angle = map(value, 0, 1023, 0, 180);
theServo.write(angle);
delay(10);
}
Project 1 Idea
I am thinking about making an instrument for the project 1. Basiclly, a speaker will generate different sound controlling by a bunch of analog inputs. I can also add some LED to make it looks cooler.