https://www.pjrc.com/teensy/td_libs_AltSoftSerial.htmlAltSoftSerial is capable of running up to 31250 baud on 16 MHz AVR
// Integers for Irvings code
word maxSpeedVal; // !!! should be 'word' now that the value is above 255 (limit of unsigned char)
word speed; // int (16 bit) - signed number from -32768 to 32767
word direction; // int (16 bit) - signed number from -32768 to 32767
...Ummm not sure why you wish to invert anything.If i can invert the signal (not sure that i can) i will try to use hardware serial with jumpers to pins 9/6.
woodygb wrote:...Ummm not sure why you wish to invert anything.If i can invert the signal (not sure that i can) i will try to use hardware serial with jumpers to pins 9/6.
.... I ASSumed there was a technical reason to not use Serial.
Byte 0: Joystick speed reading (7 MSbs)
Byte 1: Joystick direction reading (7 MSbs)
Byte 2: Speed pot reading (7 MSbs)
Byte 3:
bit 6: Speed pot reading LSb
bits 5-3: Joystick speed reading (3 LSbs)
bits 2-0: Joystick direction reading (3 LSbs)
...for your other , power down , project.4. Power-down behaviour
The SR sends the SPM its power button state. When the SPM receives a button state that it interprets as a request to power
down, it shall set the "Power Down Now" bit in its General Information packet to the SR. Note that the "power down now" bit
shall not be set until the power button is released. The SPM may also set the "Power Down Now" bit for other reasons, such as
sleep.
In response to the SPM's Power Down Now bit, the SR shall set its "Power Down / Sleep Mode Confirm" bit.
When the SPM sees the SR's "Power Down / Sleep Mode Confirm" bit, it shall physically power down.
If communication is lost with the SR without the "power down now" bit set, the SPM shall power down after 5000ms.
maxSpeedVal = 1023; // this is a fixed value ...1023 being full speed on the Shark Remote
data[0] = (0x60); // Packet type identifier
data[1] = 0x80 | ((speed >> 3) & 0x7f); // Joystick speed reading (7 MSbs)
data[2] = 0x80 | ((direction >> 3) & 0x7f); // Joystick direction reading (7 MSbs)
data[3] = 0x80 | ((maxSpeedVal) & 0x7f); // SpeedVal pot reading (7 MSbs)
data[4] = 0x80 | ((maxSpeedVal & 0x1) << 6) | ((speed & 0x7) << 3) | (direction & 0x7);
data[5] = 128; // default horn off 128 , horn on value is 130
data[6] = 132; // Value read during data capture, taken to be the 'on' value.
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
// Checksum calculations - thanks to Irving,Jim and Tony
byte sum = 0;
for (int i = 0; i < 8; i++)
sum += data[i] & 0x7f;
data[8] = (255 - (sum & 127));
data[9] = 15; // all packets end with this identifier
Type 00 SR General Information
This packet contains the joystick speed and direction ( 10 bit readings), speed pot setting (8 bit reading), and input and status
bits.
There are 28 (256) different possible values for 8 bits. When unsigned, it has possible values ranging from 0 to 255, when signed, it has -128 to 127.
// Integers for Irvings code
unsigned char maxSpeedVal; // unsigned char, same as byte (8 bit) - unsigned number from 0-255
....................................................................................................
// Code thanks to Irvings bit genius.
maxSpeedVal = 255; // this is a fixed value ...255 being the highest 8bit number it will accept
data[0] = (0x60); // Packet type identifier
data[1] = 0x80 | ((speed >> 3) & 0x7f); // Joystick speed reading (7 MSbs) 10bit number
data[2] = 0x80 | ((direction >> 3) & 0x7f); // Joystick direction reading (7 MSbs) 10bit number
data[3] = 0x80 | ((maxSpeedVal >> 1) & 0x7f); // SpeedVal pot reading (7 MSbs) 8bit number
Return to Everything Powerchair
Users browsing this forum: iainsherriff, mrgus2u and 60 guests