Created
January 18, 2020 17:38
-
-
Save carneeki/3a1459278b184c06be53f69aa0ab7743 to your computer and use it in GitHub Desktop.
David Bike Controller.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Send an RC-style PWM signal to motor controller | |
* given analog input. 2 inputs to permit joystick | |
* | |
* Designed for use on ATTiny85 w/ Arduino | |
*/ | |
#include <Servo.h> | |
#define PIN_PWM 0 // motor controller pin | |
#define PIN_IN A1 // analog input pin | |
#define DEADBAND 16 // deadband for analog value when mapped from 0 to 1023 | |
#define DELAYMS 20 // delay between loop runs | |
Servo motor; // RC servo object | |
int val; // val is position of joystick | |
void setup() { | |
pinMode(PIN_IN, INPUT); | |
motor.attach(PIN_PWM); | |
} | |
void loop() { | |
val = analogRead(PIN_IN); // read PIN_IN value | |
val = (abs(val - 512) <= DEADBAND ) 0 : val; // apply dead band filter | |
motor.write(map(val, 0, 1023, 0, 180)); // send val to motor | |
delay(DELAYMS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment