Skip to content

Instantly share code, notes, and snippets.

@cschmittiey
Created January 19, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cschmittiey/268012fe7e233df4d152 to your computer and use it in GitHub Desktop.
Save cschmittiey/268012fe7e233df4d152 to your computer and use it in GitHub Desktop.
//////////////////////////////////////////////////////////////////////////////
//
// Harley Davidson Handlebar Control Interface
//
// Written by: Len Shelton
// License: Attribution-ShareAlike 2.0
// http://creativecommons.org/licenses/by-sa/2.0/legalcode
//
//////////////////////////////////////////////////////////////////////////////
#define outputPin 13
#define in1 2 // left common
#define in2 3 // +
#define in3 4 // audio
#define in4 5 // -
#define in5 6 // dn
#define in6 7 // sel
#define in7 8 // right common
unsigned int VOL_UP[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,1,0};
unsigned int VOL_DN[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,1,0,0,1,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,1,0};
unsigned int MUTE[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,0,1,0,1,0,0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,1,0,1,0};
unsigned int SOURCE[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,1,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,1,0};
unsigned int SEEK_UP[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0};
unsigned int TRK_UP[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,1,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,1,0,1,0,1,0};
unsigned int TRK_DN[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,0,1,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0};
unsigned int DISC_UP[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,1,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0};
unsigned int DISC_DN[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0};
unsigned int ANSWER[49] = {0,1,0,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1,0,0 ,0,1,0,0,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0};
void setup()
{
pinMode(outputPin, OUTPUT);
digitalWrite(outputPin, HIGH);
pinMode(in1, INPUT);
pinMode(in2, INPUT);
pinMode(in3, INPUT);
pinMode(in4, INPUT);
pinMode(in5, INPUT);
pinMode(in6, INPUT);
pinMode(in7, INPUT);
digitalWrite(in1, HIGH); // turn on internal pullups
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, HIGH);
digitalWrite(in5, HIGH);
digitalWrite(in6, HIGH);
digitalWrite(in7, HIGH);
Serial.begin(9600);
Serial.println("start");
}
void loop()
{
check_switches();
delay(100);
}
void check_switches()
{
pinMode(in1, OUTPUT); // set the left common to input
digitalWrite(in1, LOW); // then bring it low
int read = 0;
read = digitalRead(in2); // now read 4 of the switches
if(read == 0)
{
Serial.println("+");
send(VOL_UP);
}
read = digitalRead(in3);
if(read == 0)
{
Serial.println("audio");
send(MUTE);
}
read = digitalRead(in4);
if(read == 0)
{
Serial.println("-");
send(VOL_DN);
}
read = digitalRead(in7);
if(read == 0)
{
Serial.println("up");
send(TRK_UP);
}
pinMode(in1, INPUT); // set the left common back to input so it floats
pinMode(in7, OUTPUT); // set the right common to input
digitalWrite(in7, LOW); // then bring it low
read = digitalRead(in5);
if(read == 0)
{
Serial.println("dn");
send(TRK_DN);
}
read = digitalRead(in6);
if(read == 0)
{
Serial.println("sel");
send(SOURCE);
}
digitalWrite(in7, HIGH); // bring right common back up
pinMode(in7, INPUT);
}
boolean send(unsigned int *command)
{
digitalWrite(outputPin, LOW);
delay(10);
digitalWrite(outputPin, HIGH);
delayMicroseconds(4500);
for (int x = 0; x < 49; x++)
{
if (command[x] == 0)
{
digitalWrite(outputPin, LOW);
}
else
{
digitalWrite(outputPin, HIGH);
}
delayMicroseconds(1000);
digitalWrite(outputPin, HIGH);
delayMicroseconds(200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment