-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalogRW.ino
More file actions
38 lines (34 loc) · 1.03 KB
/
analogRW.ino
File metadata and controls
38 lines (34 loc) · 1.03 KB
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
/*
[ATmega32U4 Pinout]
----------
TX=1-| ProMicro |-RAW
RX=0-| |-GND
GND-| |-RST
GND-| |-VCC
SDA=2-| |-21=A3
SCL=3(~)-| |-20=A2
A6=4-| |-19=A1
5(~)-| |-18=A0
A7=6(~)-| |-15=SCLK
7-| |-14=MISO
A8=8-| |-16=MOSI
A9=9(~)-| |-10(~)=A10
----------
*/
#define analogWritePin 17 // RX_LED
void setup()
{
Serial.begin(115200);
}
void loop()
{
unsigned int sensorValue = analogRead(A0); // read the analog in value
unsigned int pwmValue = map(sensorValue, 0, 1023, 0, 255); // analogRead(0~1023), analogWrite(0~255)
analogWrite(analogWritePin, pwmValue); // change the analog out value:
Serial.print("sensor = [");
Serial.print(sensorValue);
Serial.print("]\t PWM = [");
Serial.print(pwmValue);
Serial.println("]");
delay(1000);
}