4:f2435adf8a83 default tip
Anton Shestakov <av6@dwimlabs.net>, Mon, 08 Jun 2015 16:21:49 +0800
docs: new url

previous change 0:d3c896ca5a17

car2wd_bt/car2wd_bt.ino

Permissions: -rw-r--r--

Other formats: Feeds:
#include <VirtualWire.h>
#define IN1 3
#define IN2 5
#define IN3 6
#define IN4 11
unsigned long lastmsg = 0;
int lspd = 0, rspd = 0;
void setup() {
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
int a = Serial.parseInt();
int b = Serial.parseInt();
if (Serial.read() == '\n') {
lspd = a;
rspd = b;
lastmsg = millis();
}
} else {
unsigned int fade = (millis() - lastmsg) / 1000;
//lspd /= fade;
//rspd /= fade;
}
if (lspd > 0) {
analogWrite(IN3, map(lspd, 0, 127, 0, 255));
digitalWrite(IN4, LOW);
} else {
digitalWrite(IN3, LOW);
analogWrite(IN4, map(lspd, 0, -128, 0, 255));
}
if (rspd > 0) {
analogWrite(IN1, map(rspd, 0, 127, 0, 255));
digitalWrite(IN2, LOW);
} else {
digitalWrite(IN1, LOW);
analogWrite(IN2, map(rspd, 0, -128, 0, 255));
}
}