-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1984.ino
58 lines (44 loc) · 1.56 KB
/
1984.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on the value obtained
by analogRead().
The circuit:
- potentiometer
center pin of the potentiometer to the analog input 0
one side pin (either one) to ground
the other side pin to +5V
- LED
anode (long leg) attached to digital output 13 through 220 ohm resistor
cathode (short leg) attached to ground
- Note: because most Arduinos have a built-in LED attached to pin 13 on the
board, the LED is optional.
created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput
*/
int sensorPin = 4; // select the input pin for the potentiometer
//int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
const int audioPin = 23; // Use PWM pin for tone generation
int hz = 2000;
void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(115200);
pinMode(sensorPin, INPUT);
}
void loop() {
while (Serial.available() == 0) {} //wait for data available
hz = Serial.readString().toInt(); //read until timeout
Serial.println(hz);
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
delay(1);
Serial.println(sensorValue);
tone(audioPin, hz);
// Serial.println(power);
}