diff --git a/DCCHardware.c b/DCCHardware.c index ea832ca..a386478 100644 --- a/DCCHardware.c +++ b/DCCHardware.c @@ -10,7 +10,7 @@ *dos_send_premable: A packet has been made available, and so we should broadcast the preamble: 14 '1's in a row *dos_send_bstart: Each data uint8_t is preceded by a '0' *dos_send_uint8_t: Sending the current data uint8_t - *dos_end_bit: After the final uint8_t is sent, send a '0'. + *dos_end_bit: After the final uint8_t is sent, send a '1'. */ typedef enum { dos_idle, diff --git a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino index 00b5392..94dd5bc 100644 --- a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino +++ b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino @@ -42,14 +42,23 @@ void loop() { //handle reading throttle analog_value = analogRead(0); - speed_byte = (analog_value >> 2)-127 ; //divide by four to take a 0-1023 range number and make it 1-126 range. + const uint16_t dead_zone_width = 10; + if(analog_value <= (511-(.5*dead_zone_width))) + { + speed_byte = map(analog_value, 0, 511-(.5*dead_zone_width), -127, -2) + } + else if(analog_value >= (511+(.5*dead_zone_width))) + { + speed_byte = map(analog_value, 511+(.5*dead_zone_width), 1023, 2, 127) + } + else + { + if(old_speed > 0) speed_byte = 1; + else speed_byte = -1; + } + if(speed_byte != old_speed) { - if(speed_byte == 0) //this would be treated as an e-stop! - { - if(old_speed > 0) speed_byte = 1; - else speed_byte = -1; - } Serial.print("analog = "); Serial.println(analog_value, DEC); Serial.print("digital = "); @@ -58,6 +67,6 @@ void loop() { old_speed = speed_byte; } dps.update(); - + ++count; }