#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
Servo myservo; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
int potpin = A7; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int Sollwert; // Variable für den Servo im Bereich 800 bis 2000µs
int val1;
int potpin2 = A6; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin
int Sollwert2; // Variable für den Servo im Bereich 800 bis 2000µs
int val12;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
void setup() {
//Serial.begin(9600);
// Serial.println(F("Start"));
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.writeMicroseconds(1500); // PPM Signal zum Servo (Mittelstellung)
myservo2.attach(8); // attaches the servo on pin 9 to the servo object
myservo2.writeMicroseconds(1500); // PPM Signal zum Servo (Mittelstellung)
//SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
//Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
display.setFont(&FreeMonoBoldOblique12pt7b);
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void loop() {
// put your main code here, to run repeatedly:
analogReference(EXTERNAL);
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
Sollwert = map(val, 0, 1023, 500, 2500); // scale it to use it with the servo (value between 0 and 180)
myservo.writeMicroseconds(Sollwert); // sets the servo position according to the scaled value
display.setCursor(0, 12); // Start at top-left corner
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
display.clearDisplay();
display.print("MIN ");
// display.setCursor(0, 36); // Start at top-left corner
val1 = map(val, 0, 1023, 0, 100);
display.print(val1); display.print("%");
display.display();
delay(15);
// put your main code here, to run repeatedly:
analogReference(EXTERNAL);
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
Sollwert2 = map(val2, 0, 1023, 500, 2500); // scale it to use it with the servo (value between 0 and 180)
myservo2.writeMicroseconds(Sollwert2); // sets the servo position according to the scaled value
display.setCursor(0, 12); // Start at top-left corner
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
display.clearDisplay();
display.print("MAX ");
// display.setCursor(0, 36); // Start at top-left corner
val12 = map(val2, 0, 1023, 0, 100);
display.print(val12); display.print("%");
display.display();
delay(15);
}