void setup() {
pinMode(9, OUTPUT);
}
void loop() {
int onTime = analogRead(A0);
digitalWrite(9, HIGH);
//microsecond
delayMicroseconds(onTime);
digitalWrite(9, LOW);
delayMicroseconds(1023 - onTime);
}
Servo
#include<Servo.h>
Servo myServo;
void setup() {
myServo.attach(9);
}
void loop() {
int sensor = analogRead(A0);
int angle = map(snesor, 0, 1023, 0, 180);
if(millis() % 20 < 2){
myServo.write(angle);
}
//delay(20);
}
void setup() {
// nothing to do here
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(A0);
Serial.println(analogValue);
float frequency = map(analogValue, 0, 1000, 100, 1000);
tone(2, frequency, 10);
delay(10);
}
4f27a9328b005dfa7727d72756e51b86.mp4
When I let delay become 200, there's more rhythm.
13bc5a7683e984eb7f1ffbe1311292b7.mp4
The sound does get louder when I used transistor