Hi
Unter 9000 Zeichen könnte der Sketch auch IN den Post passen.
Damit sind die Mobilisten hier wesentlich glücklicher, als mit der .ino.
// Servo Tester V3 with 128x64 graphic OLED display
//
// Averton November 2018.
//Updated 2-12-2018 reduced the number of times the voltage is read and displayed. Made the voltage two decimal places. Changed the inc and dec pin numbers.
//Updated 2-3-2019 to use old servo routine to stop servo jitter. ServoTimer1 uses the hardware to generate servo pulses and is therefore stable
#include "SSD1X06.h"
#include <ServoTimer1.h>
ServoTimer1 testServo;
int testtime = 93;
void setup() {
SSD1X06::start();
delay(300);
SSD1X06::fillDisplay(' ');
SSD1X06::displayString6x8(0, 4, "Averton Engineering", 0);
SSD1X06::displayString6x8(1, 4, F(" Servo Tester"), 0);
SSD1X06::displayString6x8(3, 0, F("Battery Volts ="), 0);
SSD1X06::displayString6x8(5, 4, F("Servo pulse ="), 0);
for (int x = 0; x < 128; x++) {
uint8_t b = 0x81; // baseline
if (x == 0 || x == 127) {
b |= 0xFF; //
}
SSD1X06::displayByte(6, x, b);
}
SSD1X06::displayString6x8(7, 0, F("1000"), 0);
SSD1X06::displayString6x8(7, 52, F("1500"), 0);
SSD1X06::displayString6x8(7, 104, F("2000"), 0);
analogReference(INTERNAL);
testServo.attach(9);
testServo.write(93); //93=1500uS centres the servo
pinMode(2, INPUT);
pinMode(3, INPUT);
}
int voltagePin = 1;
int voltageValue = 0;
float volts;
char volts_buff[4];
int servotime = 1500;
char servotime_buff[4];
unsigned char line_position = 62;
void loop() {
if(digitalRead(2)==LOW || digitalRead(3)==LOW)servo_continuous();
servo_test();
}
void servo_continuous(){
do{
for(servotime=1000;servotime<=2000;servotime++){ //moves servo from 1mS to 2mS
if(servotime%50 == 0){ //get analog voltage every 50 steps
voltageValue = analogRead(voltagePin); //reference voltage 1.1V
volts=voltageValue*0.00974; //voltage divider 1.2K & 10K
dtostrf(volts, 4, 2, volts_buff); //convert float to text string to two decimal place - not rounded
SSD1X06::displayString6x8(3, 90, volts_buff, 0); //displays the voltage 3 lines down 90 chars across
}
dtostrf(servotime, 4, 0, servotime_buff); //converts servotime to a string of 4 chars
SSD1X06::displayString6x8(5, 82, servotime_buff, 0); //displays servotime at line 5 char 82
if(line_position !=0)SSD1X06::displayByte(6, line_position, 0x81); //turns off current vertical line on bar graph
line_position=(servotime-1000)/8; //calculates new line position
SSD1X06::displayByte(6, line_position, 0xff); //displays vertical line on bar graph
testServo.write(servotime/10.2-54); //updates the servo position pulse
}
for(servotime=2000;servotime>=1000;servotime--){ //same as above only moves servo back from 2mS to 1mS
if(servotime%50 == 0){
voltageValue = analogRead(voltagePin);//reference voltage 1.1V
volts=voltageValue*0.00974; //voltage divider 1.2K & 10K
dtostrf(volts, 4, 2, volts_buff); //convert float to text string to two decimal place - not rounded
SSD1X06::displayString6x8(3, 90, volts_buff, 0);
}
dtostrf(servotime, 4, 0, servotime_buff);
SSD1X06::displayString6x8(5, 82, servotime_buff, 0);
if(line_position !=0)SSD1X06::displayByte(6, line_position, 0x81);
line_position=(servotime-1000)/8;
SSD1X06::displayByte(6, line_position, 0xff);
testServo.write(servotime/10.2-54);
}
}while(!(digitalRead(2)==LOW || digitalRead(3)==LOW)); //if either button is pressed at the end of up and back sweep then goes to manual servo movement
servotime=1500; //centre servo
}
void servo_test(){
uint8_t count;
while(true){
for(count=0;count <=50;count++){
if(digitalRead(3)==LOW && servotime < 2000)servotime++; //if servo position is less than 2mS and inc button is pressed then increment the servo position
if(digitalRead(2)==LOW && servotime > 1000)servotime--; //if servo position is greater than 1mS and dec button is pressed then decrement the servo position
if(digitalRead(2)==LOW && digitalRead(3)==LOW){ //if both inc & dec buttons are pressed return to centre 1.5mS servo position
servotime=1500;
delay(500); //delay 1/2 a second
}
dtostrf(servotime, 4, 0, servotime_buff); //converts servotime to a string of 4 chars
SSD1X06::displayString6x8(5, 82, servotime_buff, 0); //displays servo time at row 5 char 82
if(line_position !=0)SSD1X06::displayByte(6, line_position, 0x81); //turns off current vertical line on bar graph
line_position=(servotime-1000)/8; //calculates new line position
SSD1X06::displayByte(6, line_position, 0xff); //displays vertical line on bar graph
testServo.write(servotime/10.2-54); //updates the servo position pulse
}
voltageValue = analogRead(voltagePin); //reference voltage 1.1V
volts=voltageValue*0.00974; //voltage divider 1.2K & 10K
dtostrf(volts, 4, 2, volts_buff); //convert float to text string to two decimal place - not rounded
SSD1X06::displayString6x8(3, 90, volts_buff, 0); //displays the voltage 3 lines down 90 chars across
}
}
Die Fehlermeldung besagt klipp und klar: Dir fehlt die ServoTimer1.h
Tommy56 wird wohl das Richtige dazu gesagt haben.
MfG