I'm doing project on force sensing resistors and flex sensors with wireless communication using SKXBEE (Cytron)
I'm using Serial1 to send the output to Xbee, but I can't get any data from Leonardo, is the coding wrong? Need some help here~
int outputFSR = 0;
int outputFlex = 0;
int SensorPins[] = {0,1,2,3,4,5,6,7,8,9}; // set the analog pins (connected to FSRs and Flex Sensor) into an array
int SensorCount = 10 ; // number of sensors on the insole
int sensorArray[] = {}; // set the voltage values into an array
void setup()
{
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Serial1.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop()
{
// read the FSR analog values:
for (int thisPin = 0; thisPin < SensorCount; thisPin++)
{
if ( SensorPins[thisPin]==0||SensorPins[thisPin]==9)
{
//for flex sensor only
int FlexValue = analogRead(SensorPins[thisPin]);
outputFlex = map(FlexValue, 700, 800, 0, 255);
sensorArray[thisPin] = outputFlex;
}
else
{
//for FSR values
int FSRValue = analogRead(SensorPins[thisPin]);
// map it to the range of the 8-bit analog output:
outputFSR = map(FSRValue, 0, 1023, 0, 255);
sensorArray[thisPin] = outputFSR;
// store each sensor value into an array
}
// Send the values to Xbee
Serial1.print("Sensor ");
Serial1.print(thisPin);
Serial1.print(" = ");
Serial1.println(sensorArray[thisPin]);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(450);
}
}
