Pages: [1]   Go Down
Author Topic: Using Serial To Control An LED  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to control an led with serial commands... I want to type "on" and "off" to control the led...

Here is the code I stated to write:
Code:
int ledPin = 13;

void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{

}
Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

please help! i tried, and it didnt work!
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 572
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You haven't written anything yet! How can we help you?

Also, did you realise there is an example built into the Arduino IDE which does this? File -> Examples -> Communication -> PhysicalPixel

It uses "H" and "L" to turn it on/off, but I'm sure you can adapt it...
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might take a look at Bitlash, which you will find at at http://bitlash.net -- Bitlash is a serial interpreter which runs entirely on Arduino, and it supports "macros" which are stored sequences of operations.

Here is how you might define on and off for your requirements:

Code:
> startup:="pinmode(13,1)"
> on:="d13=1"
> off:="d13=0"

Then you can say:
Code:
> on
or
Code:
> off

And the pin D13 will turn on and off, controlling your LED.

Happy hacking,

-br
http://bitlash.net
http://entropymouse.com
Logged

Pages: [1]   Go Up
Jump to: