Here is my code for running a Toyota with an Arduino
http://www.arduino.cc
Code://calibrated voltage ranges for FJ cruiser with 3.3K ohm resistor inline //used +/- 20 steps to account for voltage fluctuations #define MODEMIN 0 #define MODEMAX 20 #define VOLDNMIN 475 #define VOLDNMAX 515 #define VOLUPMIN 215 #define VOLUPMAX 255 #define SEEKDNMIN 70 #define SEEKDNMAX 110 #define SEEKUPMIN 0 #define SEEKUPMAX 20 //use this same enum in software to read key values back out #define KEY_NONE 0 #define KEY_MODE 1 #define KEY_VOLDN 2 #define KEY_VOLUP 4 #define KEY_SEEKDN 8 #define KEY_SEEKUP 16 #define KEY_ALL 31 int inputMode = 0; //analog inputs on physical board for mode button int inputVolSeek = 1; //combined inputs for volume and seek buttons int mode = 0; int volseek = 0; int lastkeycode = KEY_NONE; int keycode = KEY_NONE; void setup() { Serial.begin(57600); // initialize serial communication with computer } void loop() { mode = analogRead(inputMode); // read from the sensor volseek = analogRead(inputVolSeek); keycode = KEY_NONE; //reset keycode to nothing //binary OR any values found into single keycode output if (mode >= MODEMIN && mode <= MODEMAX) { keycode |= KEY_MODE; } if (volseek >= VOLDNMIN && volseek <= VOLDNMAX) { keycode |= KEY_VOLDN; } if (volseek >= VOLUPMIN && volseek <= VOLUPMAX) { keycode |= KEY_VOLUP; } if (volseek >= SEEKDNMIN && volseek <= SEEKDNMAX) { keycode |= KEY_SEEKDN; } if (volseek >= SEEKUPMIN && volseek <= SEEKUPMAX) { keycode |= KEY_SEEKUP; } //reduce amount of traffic, and keep events to a minimum if (keycode != lastkeycode) { Serial.println(keycode); } lastkeycode = keycode; }



LinkBack URL
About LinkBacks




Reply With Quote



glad to have you aboard(even if thread has been around for a while)

Bookmarks