Editing examples

Hey, im currently trying to edit the physical pixel code so that i can input words to move the led on and off and i hope to get this working with positioning with a servo motor however im getting really confused with it. I have tried to edit the code so i can use a word instead of a character and the board is recognising the key presses but when i hit enter the led does not change. I tried changing the int incomingByte; line to word incomingByte; but this did not solve my problem, any chances anybody knows how i could do this? Im new to this arduino stuff and im finding it really interesting but its difficult to get to grips with at the moment. Any suggestions would be very much appreciated.

Hey, I'm currently trying to edit the physical pixel code...

It would be much easier to help you if we could see your code.

If you have something in the code now named incomingByte, and it is appropriately named, it implies that you are reading data from the serial port.

Data arrives on the serial port one byte at a time. It is up to you to put those individual bytes into an appropriately typed array (hint: look at the char type), with appropriate delimiting (C strings are NULL terminated).

How much programming experience do you have? An answer that is in terms of minutes tells us one thing; an answer in terms of years tells us another.

I tried changing the int incomingByte; line to word incomingByte;

It's worth pointing out that "word" here equates to a computer word; in the case of an Arduino, this is the same size as an "int" (though it is handled very slightly differently), or two bytes.

Hey thanks for your replies, I have been coding for a very short amount of time, I did have a short spell a couple of years ago playing around with arduino chips however my knowledge is very limited. What I am currently trying to get towards is taking RSS Feeds off the internet, taking out key words and using these as my inputs to then move a servo motor to set positions. I was trying to build up the code in pieces to get a deeper knowledge. Here is my code for the part i originally posted about:

const int ledPin = 13; // the pin that the LED is attached to int incomingByte; // a variable to read incoming serial data into

void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); }

void loop() { // see if there's incoming serial data: if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it's a capital H (ASCII 72), turn on the LED: if(incomingByte == 'rain') { digitalWrite(ledPin, HIGH); } // if it's an L (ASCII 76) turn off the LED: if (incomingByte == 'change') { digitalWrite(ledPin, LOW); } } }

There is a book that describes doing something very much like what you want to do:

http://oreilly.com/catalog/9780596155520

Note who the author is. Very much worth getting.

if(incomingByte == 'rain') {

Quick critique: "rain" (note the double quotes) would be a string, (a sequence of "char"s terminated with a null) so five characters long. "incomingByte" is an "int", so the comparison is meaningless.

However, "Serial.read" only ever supplies single characters, so you need to read characters one-at-a-time into an array, and then use "strcmp" to compare them, when you think you've got enough characters. Don't forget to terminate your incoming string before using "strcmp".

Hey, thanks PaulS, i already have the book and this is what i was trying to use but i have been concentrating on getting my processing side of the code to work up until now. I have managed to get my code to read the Rss feed from the website i require but there is still a lot in the code i do not require i think. The arduino side of the code i am trying to work out as we speak and i am currently trying to change the r, g, b hex codes around so i can have full words. Does this mean that i will have to have the ASCII character numbers for all my letters i need? i had a look into this last night but i am slightly struggling to get my head round it. I am struggling with the different parts of the writing the code for my outputs. Thank you very much to AWOL too for getting back to me on this again, i had looked at this last night but was struggling to make 100% sense of it but i shall look into it again. The way you have phrased it has made a bit more sense rather than reading just all the different int's and char etc. Cheers again for your help