Recent Changes - Search:

ENTER NEW DAILY DATA HERE:

PmWiki

pmwiki.org

edit SideBar

ElmoBasicTransmitterAndReceiverCode

Transmitter:

/*
TO USE THIS CODE:
0. This code calls header file "declareElmoSlavePins.h".
   A. Copy the header file from the wiki link titled "Elmo Slave Header File," and paste into a plain text file.
   B. Save the text file as "declareElmoSlavePins" and close the text file.
   C. Rename the text file to have a ".h" extension (on the Mac, this is most easily done from the Terminal program
      using the "mv" command).
   D. Move this file into your Arduino folder
      (the Arduino folder is usually in "My Documents" on the PC, or in "Documents" on the Mac).
   E. Copy the code from this wiki page and paste it into a new Arduino sketch. Save the file with whatever name you want.
   F. Click on the drop-down menu "Sketch" and select "Add File...". Select the file "declareElmoSlavePins.h"
1. This code was written to test choreography on an ElmoSlave.
   It is assumed that you have an ElmoSlave with an Arduino board strapped to its head,
   so that you can easily upload code to try out new things. It is also assumed that your ElmoSlave
   is activated by pressing its foot-button.
   Wiring up Elmo's foot-button:
   black wire from foot: connect to ground (any ground available on pcb or arduino board)
   green wire from foot: connect to switchPin (whatever pin you pick on the Arduino to detect that the switch was pressed)
2. Modify the code to creat a new choreography, turn on the ElmoSlave, plug in the USB cable to connect
   your computer to the ElmoSlave, and upload your new code.
3. Press the foot-button and watch ElmoSlave perform the choreography.
4. Fine-tune the code by adjusting the delay times and motor speeds as needed.

AUTHORS: Mike Gazes, Nick Wong, Soyoung Park, Eric Beug
DATE: 17 February 2009
TO DO:
  1. 
See additional comments at end of file.
 */

int switchPin = 2;
int previousState=0;
int nowState=0;
int stateChange=0;
int ledPin=13; //to double check that code is good
int stepNumber = 10;

void setup() {
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH); //enable internal pull-up resistor
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}
void loop(){
state();
  if (stateChange == 1 && nowState == 1){
//    Serial.println('H');
    digitalWrite(ledPin,HIGH);
    previousState=nowState;
    state();
  }
  else if (stateChange == 1 && nowState == 0){

    Serial.print(2, BYTE); //Elmo = 2
    Serial.print(101,BYTE);//ElmoID starts at 101
    Serial.print(255,BYTE);//Move = 255
    Serial.print(stepNumber, BYTE);//Move is stepNumber
    digitalWrite(ledPin,LOW);
    previousState=nowState;
    stepNumber = stepNumber + 10;
    if (stepNumber == 80) {
      stepNumber = 10;
    }
    state();
  }
}
void state(){
  nowState=digitalRead(switchPin);
  if (nowState != previousState){
    stateChange=1;
  }
  else {
    stateChange=0;
  }
}

Receiver:

int firstByte = 0;
#define ELMO 2
int secondByte = 0;
#define elmoID 101 //any number from 101 to 254
int thirdByte = 0;
#define MOVE 255
int fourthByte = 0;
int stepNumber = 0; //any number from 10 to 100


void setup(){
  Serial.begin(9600);
}
void loop(){
  if (Serial.available()>0) {
    firstByte=Serial.read();
//    Serial.println('the first byte');
    if (firstByte == ELMO) {
      while (Serial.available()==0) {
      }
      secondByte=Serial.read();
//      Serial.println('the second byte');
      if (secondByte == elmoID) {
        while (Serial.available()==0) {
        }
        thirdByte=Serial.read();
//        Serial.println('the third byte');
        if (thirdByte == MOVE) {
          while (Serial.available()==0) {
          }
          fourthByte=Serial.read();
          stepNumber=fourthByte;
          Serial.println(stepNumber);
        }
      }
    }
  }
}


Edit - History - Print - Recent Changes - Search
Page last modified on February 17, 2009, at 04:21 PM