// This sketch is to emulate the packet of data that the Shark Joystick sends
/******************************************************************************
* Author: Tony Matthews ammatthews at gmail dot com
* License: FreeBSD
******************************************************************************/
/******************************************************************************
Copyright (c) 2015, Tony Matthews
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*******************************************************************************/
// This code is incomplete and still under revision.
// Its also got junk that may not be needed,
// Early testing phases.
// Successful output of Data packet for Shark Wheelchair controller.
// Not tested on chair, just on the Logic Analyzer.
// Pulse at one second for testing, chair sends pulse every 17ish microseconds
#include <SoftwareSerial.h>
#define rxPin 10 // Digital Pin10 for Receive from controller.
// this will have to be changed for the GCDuiNode as it uses this pin to communicate with the RF24
#define txPin 11 // Digital Pin11 Transmit from Shark Joystick to Controller.
// int sharkDataInt [10]; //Declare size of data packet sent from Shark Joystick
int joyStartByte; // was/is to setup/call function from new "void sharkJoyInt" .h file yet to be written.
// Names for Pins and what they are connected to
const int yPot = A0; // Y Pot input value
const int xPot = A1; // X Pot input value
// not used yet but will be one day...not that i ever dial my chair down...what's the point of going slow :P
int maxPot = A2; // Max speed dial pot
// Names for analogRead values of Analog Pots
int yPotVal;
int xPotVal;
int maxSpeedVal;
// Names for Mapped analogRead Values of Pots
int yPotValMapped;
int xPotValMapped;
// Size of data packet, tho the packets are not constrained to this size.
// This size for this packet but probably not for others.
unsigned char data[11];
unsigned long timer = 0;
// set up a new serial port
SoftwareSerial sharkSerial (rxPin, txPin, true); // TRUE sets this to invert software serial output.
void setup() {
// put your setup code here, to run once:
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
sharkSerial.begin(38400);
}
void loop() {
// Need to add
// Check for state, is Shark Joy On or OFF ??
// If OFF and button press "on" - run function 'sharkStartUp'
// If ON and button press "off" - stop serial output
// If ON and no button "on/off" - run function 'sharkOnMode'
}
void sharkStartup (){ //startup set of iverted serial data
// data set is incomplete, i will need to detect joy xy ..i think
// work in progress
{
yPotVal = analogRead(yPot);
xPotVal = analogRead(xPot);
yPotValMapped = map(yPotVal, 0, 1023, 128, 255); // Map min/max pot values to match min/max original Shark joystick values.
xPotValMapped = map(xPotVal, 0, 1012, 128, 255); // Map X values
}
{
//build serial packet
data[0] = (0x74); // Joystik packets start with this " ' " not accepted had to use hex)
data[1] = 130; // Joystick Y value
data[2] = 133; // Joystick X value
data[3] = 130; // Max speed setting via turtle/hare buttons on joystick
data[4] = 128; // Speed Fine Tune ?
data[5] = 136; // default horn off, horn on value is 130
data[6] = 205; // joystick On Value ?
data[7] = 160; // chair mode/ drive 128, tilt/aux output 129
data[8] = 128; //?
data[9] = 141; // ?
data[10] = 15; // all packets end with this identifier
}
for (unsigned char i = 0; i < 11; i++)
sharkSerial.write(data[i]);
// delay(17); //Delay to next packet being sent.
}
void sharkOnMode (){
{
yPotVal = analogRead(yPot);
xPotVal = analogRead(xPot);
yPotValMapped = map(yPotVal, 0, 1023, 128, 255); // Map min/max pot values to match min/max original Shark joystick values.
xPotValMapped = map(xPotVal, 0, 1012, 128, 255); // Map X values
}
{
// " ' " build serial packet
data[0] = (0x60); // Joystik packets start with this " ' " not accepted had to use hex
data[1] = yPotValMapped; // Joystick Y value
data[2] = xPotValMapped; // Joystick X value
data[3] = 255; // Max speed setting via turtle/hare buttons on joystick
data[4] = 192; // Speed Fine Tune ?
data[5] = 128; // default horn off, horn on value is 130
data[6] = 140; // joystick On Value ?
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
data[8] = 212; // some other XY modifier..maybe acceleration/de settings
data[9] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
sharkSerial.write(data[i]);
}
delay(1) ; // 1.718ms till next "a" packet
{
// " a " build serial packet
data[0] = (0x61); //
data[1] = 146; //
data[2] = 128; //
data[3] = 192; //
data[4] = 128; //
data[5] = 128; //
data[6] = 128; //
data[7] = 128; //
data[8] = 204;
for (unsigned char i = 0; i < 9; i++)
sharkSerial.write(data[i]);
}
delay(1);
sharkSerial.write(0x0f);
delay(17); //Delay next packet 17ms input from Shark joystick
}
[code]
// This sketch is to emulate the packet of data that the Shark Joystick sends
/******************************************************************************
* Author: Tony Matthews ammatthews at gmail dot com
* License: FreeBSD
******************************************************************************/
/******************************************************************************
Copyright (c) 2015, Tony Matthews
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*******************************************************************************/
// This code is incomplete and still under revision.
// Its also got junk that may not be needed,
// Early testing phases.
#include <SoftwareSerial.h>
// Names for Pins and what they are connected to
const int rxPin = 0; // Digital Pin 0 for Receive from Motor controller.
// getting ready to use GCDuiNode with the RF24 or Wii Nunchuck (currently hard wired)
const int txPin = 1; // Digital Pin 1 Transmit from Shark Joystick to Motor Controller.
const int onOffPin = 2; // Digital Pin 2 is the software on/off button
boolean onOffstate = LOW; //name holder for what the state is at the moment.
const int yPot = A0; // Y Pot input value
const int xPot = A1; // X Pot input value
const int maxPot = A2; // Max speed dial pot
// Names for analogRead values of Analog Pots
int yPotVal;
int xPotVal;
int maxSpeedVal;
// Names for Mapped analogRead Values of Pots
int yPotValMapped;
int xPotValMapped;
// Size of data packet, tho the packets are not constrained to this size.
// This size for this packet but probably not for others.
unsigned char data[11];
unsigned long timer = 0;
// set up a new serial port
// digitalWrite(rxPin, LOW); //attempting to get RX to start low before going high when 'on'state
SoftwareSerial sharkSerial (rxPin, txPin, true); // TRUE sets this to invert software serial output.
// i may need to comment out some lines of the .file to let the RX start off low.
void setup() {
// define pin modes for tx, rx:
// not sure its needed, seems to work when commented out
pinMode(rxPin, INPUT); // software serial inverted recieve pin
pinMode(txPin, OUTPUT); // softwaer serial inverted transmit pin
pinMode(13, OUTPUT); // Arduino led to monitor on or off state.
pinMode(onOffPin, INPUT_PULLUP); // Software on/off button, turn on internal pull up resistors.
//i think .end is in right place, may need to go higher in script ?
Serial.end(); // allow software serial to use Hardware UART
// start & set the data rate for the SoftwareSerial port
sharkSerial.begin(38400);
}
void loop() {
// Starts in Off state from physical power on.
// Check state, if "on" , "turn off".
if (digitalRead(onOffPin) == LOW && onOffstate == HIGH)
{
onOffstate = !onOffstate; //toggles onOffstate from HIGH to LOW (if it was HIGH when the on/off button is pressed)
digitalWrite(txPin, LOW); // hold txPin low
digitalWrite(13, onOffstate); // Turn off the LED on arduino as indication of state
delay (300); //debounce switch delay
}
// check state, if on/off button is pressed, change state to on and run start up sequence.
else if (digitalRead(onOffPin) == LOW && onOffstate == LOW)
{
onOffstate = !onOffstate; // toggle state to HIGH if in'off mode' and on/off button is pressed
digitalWrite(13, onOffstate); // turn on LED pin to get visual indication of on/off state
sharkStartup(); // call function sharkStartup()
delay(11); // delay 11ms before calling sharkOnMode() per next if statement.
}
if (onOffstate == HIGH)
{
digitalWrite(13, onOffstate); //Keep arduino LED 'on' as indication of mode arduino is in
sharkOnMode(); // Call sharkOnMode() to write joystick data to inverted serial bus
}
}
// Dynamic Shark start up sequence, inverted serial data.
void sharkStartup () {
// data set is incomplete
// work in progress
// Power On sequence, High for .293seconds, low for 10.23ms, write 't' packet, low 2.3ms
{
digitalWrite(txPin, HIGH);
delay(293);
digitalWrite(txPin, LOW);
delay(10);
}
{
//build serial packet
data[0] = (0x74); // start identifier...handshake ? " t "
data[1] = 130; // Joystick Y value
data[2] = 133; // Joystick X value
data[3] = 130; // Max speed setting via turtle/hare buttons on joystick
data[4] = 128; // Speed Fine Tune ?
data[5] = 136; // default horn off, horn on value is 130
data[6] = 205; // joystick On Value ?
data[7] = 160; // chair mode/ drive 128, tilt/aux output 129
data[8] = 128; //?
data[9] = 141; // ?
data[10] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 11; i++)
sharkSerial.write(data[i]);
}
delay(2); // delay before next handshake? packet
// build next handshake packet
{
sharkSerial.write(0x05);
sharkSerial.write(0x80);
sharkSerial.write(0xFA);
}
delay(1); // delay before close identifier "15"
sharkSerial.write(0x0F);
delay(11); //delay 12ms before sending single sharkOnMode() packet.
sharkOnMode(); // write one "0x60" packet and one "a" packet
// delay(11); //delay 11.71ms before sending single sharkThridpacket()
// delay not needed as previous sharkOnMode() has delay at end already.
sharkThirdpacket (); // write one third packet
}
void sharkThirdpacket () {
//this third packet of data is very similar to the sharkOnMode but
//"0x60" section, 1.6ms pause low, "a" section, .6ms low, "26,133,167,185"
{
// " ' " build serial packet
data[0] = (0x60); // Joystik packets start with this
data[1] = yPotValMapped; // Joystick Y value
data[2] = xPotValMapped; // Joystick X value
data[3] = 255; // Max speed setting via turtle/hare buttons on joystick
data[4] = 192; // Speed Fine Tune ?
data[5] = 128; // default horn off, horn on value is 130
data[6] = 140; // joystick On Value ?
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
data[8] = 212; // some other XY modifier..maybe acceleration/de settings
data[9] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
sharkSerial.write(data[i]);
}
delay(1) ; // 1.718ms till next "a" packet
{
// " a " build serial packet
data[0] = (0x61); //
data[1] = 146; //
data[2] = 128; //
data[3] = 192; //
data[4] = 128; //
data[5] = 128; //
data[6] = 128; //
data[7] = 128; //
data[8] = 204;
for (unsigned char i = 0; i < 9; i++)
sharkSerial.write(data[i]);
}
delay(1);
{
// build "26,133,167,185" packet
data[0] = 26;
data[1] = 133;
data[2] = 167;
data[3] = 185;
for (unsigned char i = 0; i < 4; i++)
sharkSerial.write(data[i]);
}
delay(1);
sharkSerial.write(0x0f);
}
// function to write: emulated, inverted, serial data.
void sharkOnMode () {
{
yPotVal = analogRead(yPot);
xPotVal = analogRead(xPot);
yPotValMapped = map(yPotVal, 0, 1023, 128, 255); // Map min/max pot values to match min/max original Shark joystick values.
xPotValMapped = map(xPotVal, 0, 1012, 128, 255); // Map X values
}
{
// " ' " build serial packet
data[0] = (0x60); // Joystik packets start with this
data[1] = yPotValMapped; // Joystick Y value
data[2] = xPotValMapped; // Joystick X value
data[3] = 255; // Max speed setting via turtle/hare buttons on joystick
data[4] = 192; // Speed Fine Tune ?
data[5] = 128; // default horn off, horn on value is 130
data[6] = 140; // joystick On Value ?
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
data[8] = 212; // some other XY modifier..maybe acceleration/de settings
data[9] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
sharkSerial.write(data[i]);
}
delay(1) ; // 1.718ms till next "a" packet
{
// " a " build serial packet
data[0] = (0x61); //
data[1] = 146; //
data[2] = 128; //
data[3] = 192; //
data[4] = 128; //
data[5] = 128; //
data[6] = 128; //
data[7] = 128; //
data[8] = 204;
for (unsigned char i = 0; i < 9; i++)
sharkSerial.write(data[i]);
}
delay(1);
sharkSerial.write(0x0f);
delay(11); //Delay next packet 17ms input from Shark joystick
}
[/code]
// This sketch is to emulate the packet of data that the Shark Joystick sends
/******************************************************************************
* Author: Tony Matthews ammatthews at gmail dot com
* License: FreeBSD
******************************************************************************/
/******************************************************************************
Copyright (c) 2015, Tony Matthews
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*******************************************************************************/
// This code is incomplete and still under revision.
// Its also got junk that may not be needed,
// Early testing phases.
#include <SoftwareSerial.h>
// Names for Pins and what they are connected to
const int rxPin = 9; // Digital Pin 0 for Receive from Motor controller.
// getting ready to use GCDuiNode with the RF24 or Wii Nunchuck (currently hard wired)
const int txPin = 12; // Digital Pin 1 Transmit from Shark Joystick to Motor Controller.
const int onOffPin = 2; // Digital Pin 2 is the software on/off button
boolean onOffstate = LOW; //name holder for what the state is at the moment.
const int yPot = A0; // Y Pot input value
const int xPot = A1; // X Pot input value
const int maxPot = A2; // Max speed dial pot
// Names for analogRead values of Analog Pots
int yPotVal;
int xPotVal;
// Names for Mapped analogRead Values of Pots
int yPotValMapped;
int xPotValMapped;
// Size of data packet, tho the packets are not constrained to this size.
// This size for this packet but probably not for others.
unsigned char data[12];
unsigned long timer = 0;
// set up a new port
SoftwareSerial sharkSerial (rxPin, txPin, true); // TRUE sets this to invert software serial output.
// i may need to comment out some lines of the .file to let the RX start off low.
void setup() {
// define pin modes for tx, rx:
// not sure its needed, seems to work when commented out
pinMode(rxPin, INPUT); // software serial inverted recieve pin
pinMode(txPin, OUTPUT); // softwaer serial inverted transmit pin
pinMode(13, OUTPUT); // Arduino led to monitor on or off state.
pinMode(onOffPin, INPUT_PULLUP); // Software on/off button, turn on internal pull up resistors.
// start & set the data rate for the SoftwareSerial port
sharkSerial.begin(38400);
}
void loop() {
// Starts in Off state from physical power on.
// Check state, if "on" , "turn off".
if (digitalRead(onOffPin) == LOW && onOffstate == HIGH)
{
onOffstate = !onOffstate; //toggles onOffstate from HIGH to LOW (if it was HIGH when the on/off button is pressed)
digitalWrite(txPin, LOW); // hold txPin low
digitalWrite(13, onOffstate); // Turn off the LED on arduino as indication of state
delay (300); //debounce switch delay
}
// check state, if on/off button is pressed, change state to on and run start up sequence.
else if (digitalRead(onOffPin) == LOW && onOffstate == LOW)
{
onOffstate = !onOffstate; // toggle state to HIGH if in'off mode' and on/off button is pressed
digitalWrite(13, onOffstate); // turn on LED pin to get visual indication of on/off state
sharkStartup(); // call function sharkStartup()
delay(11); // delay 11ms before calling sharkOnMode() per next if statement.
}
if (onOffstate == HIGH)
{
digitalWrite(13, onOffstate); //Keep arduino LED 'on' as indication of mode arduino is in
sharkOnMode(); // Call sharkOnMode() to write joystick data to inverted serial bus
}
}
// Dynamic Shark start up sequence, inverted serial data.
void sharkStartup () {
// data set is incomplete
// work in progress
// Power On sequence, High for .293seconds, low for 10.23ms, write 't' packet, low 2.3ms
{
digitalWrite(txPin, HIGH);
delay(293);
digitalWrite(txPin, LOW);
delay(10);
}
{
//build serial packet
data[0] = (0x74); // start identifier...handshake ? " t "
data[1] = 130; // Joystick Y value
data[2] = 133; // Joystick X value
data[3] = 130; // Max speed setting via turtle/hare buttons on joystick
data[4] = 128; // Speed Fine Tune ?
data[5] = 136; // default horn off, horn on value is 130
data[6] = 205; // joystick On Value ?
data[7] = 160; // chair mode/ drive 128, tilt/aux output 129
data[8] = 128; //?
data[9] = 141; // ?
data[10] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 11; i++)
sharkSerial.write(data[i]);
}
delay(2); // delay before next handshake? packet
// build next handshake packet
{
data[0] = 5; //
data[1] = 128; //
data[2] = 250; //
for (unsigned char i = 0; i < 3; i++)
sharkSerial.write(data[i]);
}
delay(1); // delay before close identifier "15"
sharkSerial.write(0x0F);
delay(11); //delay 12ms before sending single sharkOnMode() packet.
sharkOnMode(); // write one "0x60" packet and one "a" packet
// delay(11); //delay 11.71ms before sending single sharkThridpacket()
// delay not needed as previous sharkOnMode() has delay at end already.
sharkThirdpacket (); // write one third packet
}
void sharkThirdpacket () {
//this third packet of data is very similar to the sharkOnMode but
//"0x60" section, 1.6ms pause low, "a" section, .6ms low, "26,133,167,185"
{
// " ' " build serial packet
data[0] = (0x60); // Joystik packets start with this
data[1] = yPotValMapped; // Joystick Y value
data[2] = xPotValMapped; // Joystick X value
data[3] = 255; // Max speed setting via turtle/hare buttons on joystick
data[4] = 205; // Speed Fine Tune ?
data[5] = 128; // default horn off, horn on value is 130
data[6] = 140; // joystick On Value ?
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
data[8] = 200; // some other XY modifier..maybe acceleration/de settings
data[9] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
sharkSerial.write(data[i]);
}
delay(1) ; // 1.718ms till next "a" packet
{
// " a " build serial packet
data[0] = (0x61); //
data[1] = 128; //
data[2] = 192; //
data[3] = 192; //
data[4] = 128; //
data[5] = 128; //
data[6] = 128; //
data[7] = 128; //
data[8] = 158; //
for (unsigned char i = 0; i < 9; i++)
sharkSerial.write(data[i]);
}
delay(1);
{
// build "26,133,167,185" packet
data[0] = 26;
data[1] = 133;
data[2] = 167;
data[3] = 185;
for (unsigned char i = 0; i < 4; i++)
sharkSerial.write(data[i]);
}
delay(1);
sharkSerial.write(0x0f);
}
// function to write: emulated, inverted, serial data.
void sharkOnMode () {
{
yPotVal = analogRead(yPot);
xPotVal = analogRead(xPot);
yPotValMapped = map(yPotVal, 0, 1023, 128, 255); // Map min/max pot values to match min/max original Shark joystick values.
xPotValMapped = map(xPotVal, 0, 1012, 128, 255); // Map X values
}
{
// " ' " build serial packet
data[0] = (0x60); // Joystik packets start with this
data[1] = yPotValMapped; // Joystick Y value
data[2] = xPotValMapped; // Joystick X value
data[3] = 255; // Max speed setting via turtle/hare buttons on joystick
data[4] = 192; // Speed Fine Tune ?
data[5] = 128; // default horn off, horn on value is 130
data[6] = 140; // joystick On Value ?
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
data[8] = 191; // some other XY modifier..maybe acceleration/de settings
data[9] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
sharkSerial.write(data[i]);
}
delay(1) ; // 1.718ms till next "a" packet
{
// " a " build serial packet
data[0] = (0x61); //
data[1] = 128; //
data[2] = 192; //
data[3] = 192; //
data[4] = 128; //
data[5] = 128; //
data[6] = 128; //
data[7] = 128; //
data[8] = 158;
for (unsigned char i = 0; i < 9; i++)
sharkSerial.write(data[i]);
}
delay(1);
sharkSerial.write(0x0f);
delay(11); //Delay next packet 17ms input from Shark joystick
}



if (digitalRead(onOffPin) == LOW && onOffstate == HIGH)
{
onOffstate = !onOffstate; //toggles onOffstate from HIGH to LOW (if it was HIGH when the on/off button is pressed)
Serial.end(); // Allow manual control of UART RX
pinMode(rxPin, OUTPUT); // a bit of a work around to get RX UART to go LOW
digitalWrite(rxPin, LOW); //hold rxPin low when 'off'
digitalWrite(txPin, LOW); // hold txPin low when 'off'
digitalWrite(13, onOffstate); // Turn off the LED on arduino as indication of state
delay (300); //debounce switch delay
}

{
// " ' " build serial packet
data[0] = (0x60); // Joystik packets start with this
data[1] = yPotValMapped; // Joystick Y value
data[2] = xPotValMapped; // Joystick X value
data[3] = 255; // Max speed setting via turtle/hare buttons on joystick
data[4] = 205; // Speed Fine Tune ?
data[5] = 128; // default horn off, horn on value is 130
data[6] = 140; // joystick On Value ?
data[7] = 128; // chair mode/ drive 128, tilt/aux output 129
data[8] = 200; // some other XY modifier..maybe acceleration/de settings
data[9] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 10; i++)
sharkSerialy.write(data[i]);
}
delay(1) ; // 1.718ms till next "a" packet
{
// " a " build serial packet
data[0] = (0x61); //
data[1] = 128; //
data[2] = 192; //
data[3] = 192; //
data[4] = 128; //
data[5] = 128; //
data[6] = 128; //
data[7] = 128; //
data[8] = 158; //
for (unsigned char i = 0; i < 9; i++)
sharkSerialy.write(data[i]);
}

{
//build 'Yellow' serial packet
data[0] = (0x74); // start identifier...handshake ? " t "
data[1] = 130; // Joystick Y value
data[2] = 133; // Joystick X value
data[3] = 130; // Max speed setting via turtle/hare buttons on joystick
data[4] = 128; // Speed Fine Tune ?
data[5] = 136; // default horn off, horn on value is 130
data[6] = 205; // joystick On Value ?
data[7] = 160; // chair mode/ drive 128, tilt/aux output 129
data[8] = 128; //?
data[9] = 141; // ?
data[10] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 11; i++)
sharkSerialy.write(data[i]);
}
{
//build 'Blue' serial packet
data[0] = (0x74); // start identifier...handshake ? " t "
data[1] = 130; // Joystick Y value
data[2] = 133; // Joystick X value
data[3] = 130; // Max speed setting via turtle/hare buttons on joystick
data[4] = 128; // Speed Fine Tune ?
data[5] = 136; // default horn off, horn on value is 130
data[6] = 205; // joystick On Value ?
data[7] = 160; // chair mode/ drive 128, tilt/aux output 129
data[8] = 128; //?
data[9] = 141; // ?
data[10] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 11; i++)
sharkSerialb.write(data[i]);
}
gcebiker wrote:Opps, wrong bit of code in previous post
{
//build serial packet
data[0] = (0x74); // start identifier...handshake ? " t "
data[1] = 130; // Joystick Y value
data[2] = 133; // Joystick X value
data[3] = 130; // Max speed setting via turtle/hare buttons on joystick
data[4] = 128; // Speed Fine Tune ?
data[5] = 136; // default horn off, horn on value is 130
data[6] = 205; // joystick On Value ?
data[7] = 160; // chair mode/ drive 128, tilt/aux output 129
data[8] = 128; //?
data[9] = 141; // ?
data[10] = 15; // all packets end with this identifier
for (unsigned char i = 0; i < 11; i++) {
sharkSerialy.write(data[i]);
sharkSerialb.write(data[i]); }
}

gcebiker wrote:Ah HA !
I need one of these http://www.hobbytronics.co.uk/leonardo-canbus
Oh how i love the internet and gadgets, i think i was gestated in a Library..at the back of a Radio Shack.
/***************************************************************************
Hobbytronics Leonardo CAN-BUS board
Send Test Data to other nodes
Leonardo CAN BUS product page http://www.hobbytronics.co.uk/leonardo-canbus
Hobbytronics.co.uk
****************************************************************************/
#include <mcp_can.h>
#include <SPI.h>
int led = 23;
MCP_CAN CAN0(17); // Set CS to pin 17
void setup()
{
Serial.begin(9600);
delay(3000);
Serial.print("Can Test..\r\n");
// init can bus, baudrate: 40000 baud
if(CAN0.begin(CAN_40KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
else Serial.print("Can init fail!!\r\n");
pinMode(led, OUTPUT);
}
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
// send data: id = 0x00, standard frame, data len = 8, stmp: data buf
digitalWrite(led, HIGH); // turn the LED on
CAN0.sendMsgBuf(0x00, 0, 8, stmp);
delay(1000);
digitalWrite(led, LOW); // turn the LED off
delay(900); // send data every second
}
Return to Everything Powerchair
Users browsing this forum: F3Head, Jay_x, martin007 and 96 guests