//Code written by Gabriella Levine to take inputs from button pins and output //chars to the serial port // set pin numbers: const int buttonPin1 = 2; // the number of the pushbutton pin const int buttonPin2 = 3; // the number of the pushbutton pin const int buttonPin3 = 4; // the number of the pushbutton pin const int buttonPin4 = 5; // the number of the pushbutton pin const int buttonPin5 = 6; // the number of the pushbutton pin const int buttonPin6 = 7; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // variables int buttonState1 = 0; // variable for reading the pushbutton status int buttonState3 = 0; // variable for reading the pushbutton status int buttonState2 = 0; // variable for reading the pushbutton status int buttonState4 = 0; // variable for reading the pushbutton status int buttonState5 = 0; // variable for reading the pushbutton status int buttonState6 = 0; // variable for reading the pushbutton status void setup() { Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); pinMode(buttonPin6, INPUT); } void loop(){ if(Serial.available()>0){ byte incomingByte = Serial.read(); if(incomingByte=='1'||incomingByte=='2'||incomingByte=='6'||incomingByte=='5'||incomingByte=='0') { digitalWrite(ledPin, HIGH); delay(10); digitalWrite(ledPin, LOW); } } // read the state of the pushbutton value: buttonState1 = digitalRead(buttonPin1); buttonState2 = digitalRead(buttonPin2); buttonState3 = digitalRead(buttonPin3); buttonState4 = digitalRead(buttonPin4); buttonState5 = digitalRead(buttonPin5); buttonState6 = digitalRead(buttonPin6); // check if the pushbutton is pressed. if (buttonState1 == HIGH) { Serial.print('1'); } if (buttonState2 == HIGH) { Serial.print('2'); } if (buttonState4 == HIGH) { Serial.print('4'); } if (buttonState3 == HIGH) { Serial.print('3'); } if (buttonState5 == HIGH) { Serial.print('5'); } if (buttonState6 == HIGH) { Serial.print('6'); } delay(10); }

For this version of the snake, various character inputs (numbers 1-6) affect the wave behavior.OPTION 1: xbee+computer (see this instructable for more info)-Plug in xbee to the xbee explorer.-Plug xbee explorer into your computer via the USB cable.-Download and open CoolTerm -Click "OPTIONS".-Make sure the BAUD RATE is set to 57600.-Make sure that after "PORT:" it says something like "usbserial-A700xxx". If not, select "RESCAN SERIAL PORTS".-Click OK.-Click "CONNECT"-Make sure your xbee is set to 57600 baud rate:Type "+++" (you might not see anything written in the serial port unless you have checked "LOCAL ECHO" in the TERMINAL tab of the OPTIONS.)You should get "OK" returned in the serial monitor of CoolTerm. If you are not, perhaps xbee is not set to that baud rate. to debug, go back to OPTIONS and select "baud rate 9600" and try again.Now you have entered xbee's "command mode".Type "ATBD" then ENTER.(and don't wait too long or you will exit command mode).You should get an integer returned, corresponding to the baud rate xbee is set at. To make sure it is set to 57600, type "ATBD 6" then ENTER.You should get "OK" returned.Now type "ATWR".Now, when you type the characters 1-6 in the serial monitor, when the snake is turned on, the characters should affect the motion.5&6: affect the speed of the rotation of the servos.3&4: affect the period of the wave (speed of propagation down the line of servos).1&2: affect the amplitude of the wave.Visualize in software how the wave behavior is affected by the various parameters, or typing in integers 1-6..The attached graphs show the output angle values of each servo mapped over time, slightly out of phase from each other. The difference is when there is a different offset (delay in the time it takes one servo to get to the angle of the previous one in the line of waves).If you don't want to use your computer, and want to have a free standing remote control, feel free to make an arduino based r/c. To do this, plug in the xbee to an xbee shield mounted on Arduino (see image). Make a 6 button inputs . I hacked into a joystick that had 2 extra buttons. Connect the 6 buttons to Arduino digital pins 2-7.Upload the following code to arduino.And now affect the snake behavior the same way as through coolTerm.