-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ino
40 lines (30 loc) · 1.13 KB
/
main.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
#include <Servo.h>
#include <OLED_I2C.h>
Servo myservo; // create servo object to control a servo
OLED myOLED(SDA, SCL, 8);
const int increaseButton = 9;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 10;
extern uint8_t BigNumbers[];
int value = 0;
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(10); // attaches the servo on pin 9 to the servo object
myOLED.begin();
myOLED.setFont(BigNumbers);
pinMode(increaseButton,INPUT_PULLUP);
}
void loop()
{
myOLED.printNumI(val,CENTER,24);
myOLED.update();
myOLED.clrScr();
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it 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
}