When I say newbie, I'm talking about one week into this.
I am attempting to build a Google Bike http://www.instructables.com/id/Google-Bike/?ALLSTEPS . I purchased a seeeduino ATMega168, Electronic Brick Chasis, and an electronic brick joysitck. I will be using a window alarm as a reed switch.
The original sketch is listed below It calls for attaching the joysitck to analog pins 0 and 1, and the joysitck button to digital 2. The reed switch is attached to digital pin 3.
// ---- cadence sensor ----
int reedPin = 3; // Reed switch connected to digital pin
volatile byte rotationCount = 0; // will be used in interrrupt
void rotation() {
byte buff = 0x00;
for (byte i = 0; i < 8; i++) {
buff |= !digitalRead(reedPin) << i;
}
if (buff == 0xff) {
rotationCount += 1;
}
// if (!digitalRead(reedPin)) {
// if (!digitalRead(reedPin)) { // crappy debouncing
// rotationCount += 1;
// }
// }
}
// ---- joystick ----
int vPin = 0; // analog input for vertical-axis of joystick
int v = 0; // variable to store vertical-axis position
int hPin = 1; // analog input for horizontal-axis of joystick
int h = 0; // variable to store horizontal-axis position
int clickPin = 2; // digital input for push-down button on joystick
int click = 0;
// ---- protocol ----
// 001123\0 : 00 = X, 11 = Y, 2 = click, 3 = rotationCount, \0 = null termination
// 1 2 3 4 5 6 7 8 9 10
//char packet[11] = {'0','0','0','0','0','0','0','0','0','0','\0'};
// --------------------------------
void setup() {
// start serial connection to relay data to python
Serial.begin(14400); // Is this a good baud rate?
// set pin connected to reed switch to input
pinMode(reedPin, INPUT);
// set reed pin pull up resistor
digitalWrite(reedPin, HIGH);
// attach interrupt to reed pin
attachInterrupt(1, rotation, FALLING);
// configure joystick
// set press clickPin as input
pinMode(clickPin, INPUT);
// enable pull-up resistor on clickPin
digitalWrite(clickPin, HIGH);
}
void loop() {
// read analog values
v = analogRead(vPin);
h = analogRead(hPin);
click = digitalRead(clickPin);
// build packet
// packet[0] = highByte(x);
// packet[1] = lowByte(x);
// packet[2] = highByte(y);
// packet[3] = lowByte(y);
// packet[4] = byte(click);
// packet[5] = rotationCount;
// sent packet
//Serial.println(rotationCount);
Serial.print(h);
Serial.print(',');
Serial.print(v);
Serial.print(',');
Serial.print(click);
Serial.print(',');
Serial.println(rotationCount,DEC);
// Serial.println(packet);
delay(10);
}
-------------------------------------------------
with the electronic brick chasis, some of the pins from this sketch are available. I attempted to make the following modifications, using A2 and A2 and D11 and D12:
---------------
int reedPin = 11; // Reed switch connected to digital pin
volatile byte rotationCount = 0; // will be used in interrrupt
// ---- joystick ----
int vPin = 1; // analog input for vertical-axis of joystick
int v = 0; // variable to store vertical-axis position
int hPin = 2; // analog input for horizontal-axis of joystick
int h = 0; // variable to store horizontal-axis position
int clickPin = 12; // digital input for push-down button on joystick
int click = 0;
(Moderator edit: Code to code box.)
All other lines were left untouched. When I ran the program (python script) the python shell indicated that it was receiving data from hPin and vPin and clickPin (displayed values changed), but the image on the screen moved wildly around the screen.
Is the problem in my alterations of the sketch?
thanks
Goog
googlebike.pde (2.09 KB)