arduino xbee,

August 15, 2012   ·   0 Comments

 


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);

}
 int sensorValue;
void loop() {

 sensorValue = analogRead(A0);
 sensorValue=map(sensorValue,0,255,0,3);


 Serial.print(sensorValue);

}

 

</pre>
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(10, 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();

 //Serial.println(incomingByte);




 // if it's a capital H (ASCII 72), turn on the LED:

 if (incomingByte == '0') {
 //digitalWrite(ledPin, HIGH);
 // Serial.println(incomingByte);
 analogWrite(10,0);
 }
 // if it's an L (ASCII 76) turn off the LED:
 else if (incomingByte == '1') {
 // digitalWrite(ledPin, LOW);
 analogWrite(10,100);
 }else if (incomingByte == '2') {
 // digitalWrite(ledPin, LOW);
 analogWrite(10,200);
 }else if (incomingByte == '4') {
 // digitalWrite(ledPin, LOW);
 analogWrite(10,255);
 }

 }
}
<pre>


shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Hardware22

Hardware

Amazon

adsbygoogle

Recent Posts

Categories

Amazon