Go Down

Topic: Xbee and PWN (Read 362 times) previous topic - next topic

lkacenja

Aug 01, 2009, 03:21 am Last Edit: Aug 01, 2009, 03:22 am by lkacenja Reason: 1
Hi,

I'm running Processing 1.0.1 and Arduino 16. I just got a set of brand new Xbee series 1 transmitters, an Xbee shield and the Sparkfun Xbee explorer. Using the Processing serial library I was able to have a successful blink on click test via the Xbee radio. However, I was trying to modify this first test to send an analog signal to a PWN pin and I cannot seem to get it going. It accepts the first value sent and then wont change. By the way, it works fine over wired USB. Do Xbees not deal well with PWN? Here is my Arduino code:

Code: [Select]
// RECIEVER

byte incomingByte;
int val;
void setup() {

 // start serial port at 19200 bps
 Serial.begin(19200);
 Serial.println("Ready!");

 // led pins

 pinMode (9, OUTPUT);

 delay(1000);

}

void loop() {
 if (Serial.available()) {   // are there any bytes available on the serial port ???
   incomingByte = Serial.read();
   Serial.flush();
   Serial.print(int(incomingByte));
   
   analogWrite(9, incomingByte);
 }else{
   Serial.flush();
   byte incomingByte == 0;
 }
}






and here is my Processing code:

Code: [Select]
import processing.serial.*;
import controlP5.*;


ControlP5 controlP5;
Serial myPort;  // Create object from Serial class
int val;  

int sliderValue = 100;

void setup() {
 size(150,150);
 String portName = Serial.list()[0];
 myPort = new Serial(this, portName, 19200);


 controlP5 = new ControlP5(this);
 Slider s = controlP5.addSlider("slider",0,255,128,10,10,25,100);
}

void draw() {
 val  = round(controlP5.controller("slider").value());

 println(val);
 myPort.write(val);


 background(75);
 fill(sliderValue);
}




Any suggestions. Thanks for helping out a noob. I really super appreciate it.  :)

Go Up