Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wdlindmeier/lasercat
Browse files Browse the repository at this point in the history
  • Loading branch information
harryhow committed Oct 24, 2012
2 parents abf05c3 + d739bd6 commit 4ace3db
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
74 changes: 74 additions & 0 deletions Arduino/CinderSerialToIR/CinderSerialToIR.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* IRRemote ]
* NOTE: IR pin must be pin 3
*/
#include <IRremote.h>

enum {
TokenIdxLeft = 0,
TokenIdxRight,
TokenIdxSpeed,
NumTokenIdxs
};

IRsend irsend; //

void setup()
{
Serial.begin(9600);
}

void loop()
{

if(Serial.available()){

int MAX_CHAR = 100;
char readVal[MAX_CHAR];
int numChar = Serial.readBytesUntil('\n', readVal, MAX_CHAR);
String inVal = String(readVal).substring(0,numChar);
Serial.println(inVal);

if(inVal.indexOf(',') != -1){ // Steering directions

char tokens[numChar];
inVal.toCharArray(tokens, numChar);
char *token;
char *ts=tokens;
int tkIdx=0;
int tokInts[NumTokenIdxs];
while ((token = strtok_r(ts, ",", &ts)) != NULL){

if(tkIdx<NumTokenIdxs){
tokInts[tkIdx] = atol(token);
}
tkIdx++;
}

if(tkIdx == NumTokenIdxs){

long lVal = (long)tokInts[TokenIdxLeft];
long rVal = (long)tokInts[TokenIdxRight];

if(lVal > 0 && rVal > 0 && lVal < 1000 && rVal < 1000){

/*
Serial.print("lVal: ");
Serial.print(lVal);
Serial.print(" rVal: ");
Serial.println(rVal);
*/

long totalVal = (lVal*(long)1000)+rVal;
Serial.println(totalVal);
irsend.sendNEC(totalVal, 32);

}

}

}

}
}

9 changes: 5 additions & 4 deletions Cinder/SerialTest/src/SerialTestApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void SerialTestApp::setup()

void SerialTestApp::mouseDown( MouseEvent event )
{
serial.writeString("hotdog\n");
// serial.writeString("hotdog\n");
}

void SerialTestApp::mouseDrag( MouseEvent event )
Expand All @@ -64,18 +64,19 @@ void SerialTestApp::mouseDrag( MouseEvent event )
amtRightWheel = offset.y*-1;
}

int lw = amtLeftWheel*255; // -255..255
int rw = amtRightWheel*255; // -255..255
int lw = 255+(amtLeftWheel*255); // 0..255..500
int rw = 255+(amtRightWheel*255); // 0..255..500
int sp = (int)speed;
string directions = "" + boost::lexical_cast<string>((int)lw) + "," +
boost::lexical_cast<string>((int)rw) + "," +
boost::lexical_cast<string>((int)sp) + ",\n";
console() << directions << "\n";
serial.writeString(directions);
}

void SerialTestApp::mouseUp( MouseEvent event )
{
serial.writeString("hamburger\n");
// serial.writeString("hamburger\n");
}

void SerialTestApp::update()
Expand Down
Binary file not shown.

0 comments on commit 4ace3db

Please sign in to comment.