Tnx, Adam.
Previous Arduino code for Nano has some bugs. this is working version. I added kill switch option and changed TM1637 library to TM1637-1.1.0. All setup contains Arduino Nano, 4-bit seven-segment display which displays PWM in microseconds and four button remote control.
// ver. 27. feb. 2018
// kill switch input D2,
// PWM output to ESC D8,
// LED DIO D5, LED CLK D6,
// connect from GND to D2, D9-D12 10K pull-down resitors
// use TM1637-1.1.0 library from Github
#include <Servo.h> //Using servo library to control ESC
#include <TM1637Display.h> //lib. for 7 seg. display
//{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
//0~9,A,b,C,d,E,F
Servo esc; //Creating a servo class with name as esc
#define CLK 6 //pins for display
#define DIO 5
TM1637Display display(CLK, DIO);
int PWM = 1500;
void setup(){
display.setBrightness(0x0a);
delay(2000);
esc.attach(8); //Specify the esc signal pin,Here as D8
esc.writeMicroseconds(1500); //initialize the signal to 1500
display.showNumberDec(PWM);
delay(1500);
Serial.begin(9600);
Serial.println(“Inicilizacija…”);
}
void loop(){
while (digitalRead(9) == LOW && digitalRead(10) && digitalRead(11) == LOW && digitalRead(12) == LOW) {
display.showNumberDec(PWM);
}
while (digitalRead(9) == HIGH && digitalRead(2) == LOW) {
PWM = PWM+50;
PWM = constrain(PWM, 1100, 1900);
display.showNumberDec(PWM);
esc.writeMicroseconds(PWM);
Serial.println(PWM);
delay(500);
}
while (digitalRead(10) == HIGH && digitalRead(2) == LOW) {
PWM = PWM-50;
PWM = constrain(PWM, 1100, 1900);
display.showNumberDec(PWM);
esc.writeMicroseconds(PWM);
Serial.println(PWM);
delay(500);
}
while (digitalRead(11) == HIGH && digitalRead(2) == LOW) {
PWM = PWM+100;
PWM = constrain(PWM, 1100, 1900);
esc.writeMicroseconds(PWM);
display.showNumberDec(PWM);
Serial.println(PWM);
delay(500);
}
while (digitalRead(12) == HIGH) {
PWM = 1500;
esc.writeMicroseconds(PWM);
display.showNumberDec(PWM);
Serial.println(PWM);
delay(500);
}
while (digitalRead(2) == HIGH) { // if kill switch activated stop esc
PWM = 1500;
esc.writeMicroseconds(PWM);
display.showNumberDec(PWM);
Serial.println(PWM);
delay(1000);
}
}