Hi everyone. This is my first attempt at C code programming. I have used idea oriented languages like Python and MATLAB, but C is giving me some trouble.
I am trying to use the Arduino and the TouchShield to monitor a couple of pressures and temperatures in my car. Right now I just have one 50 PSIA pressure sensor. The problem is when boost_max is printed to the TouchShield using the text() command. It looks like the four digit character array is bein printed several times across the screen. The text that is specified by the code is deleted and overwritten correctly when the boost_max array is updated, but the excess text is just overwritten. I am not sure if this lends any clues.
Arduino Code:
//This code should be downloaded onto the Arduino
#include "NewSoftSerial.h"
#define RXPIN 3 //3
#define TXPIN 2 //2
NewSoftSerial mySerial(RXPIN,TXPIN);
int val=0;
float boost=0;
float boost_max=0;
void setup()
{
pinMode(RXPIN, INPUT);
pinMode(TXPIN, OUTPUT);
mySerial.begin(9600);
}
void loop()
{
//mySerial.print(123456);
val = analogRead(0);
boost = val*.0049; // A/D conversion
boost = boost*(50/4)-(50/4*0.5); // Applying scaling
mySerial.print(1);
mySerial.print(boost);
delay(500);
if (boost > boost_max)
{
boost_max = boost;
mySerial.print(2);
mySerial.print(boost);
delay(200);
}
}
TouchShield Slide Code:
//This code should be downloaded onto the TouchShield Classic or Steath
char input[5];
char boost_max[4];
char output[4];
void setup()
{
Serial.begin(9600);
background(0,0,0);
stroke(0,255,0);
text("Manifold Pressure",40,40,14);
stroke(255,0,0);
text("PSI",220,80,24);
stroke(0,255,0);
text("Maximum Pressure",40,120,14);
stroke(255,0,0);
text("PSI",220,160,24);
}
void loop()
{
if (Serial.available()>5)
{
for (int i=0; i <= 5; i++)
{
input[i] = Serial.read();
}
// Serial.flush();
}
if (input[0] == '1')
{
stroke(0,0,0);
text(output,60,80,24);
for (int k=0; k <= 4; k++)
{
output[k]=input[k+1];
}
stroke(255,0,0);
text(output,60,80,24);
delay(10);
}
if (input[0] == '2')
{
stroke(0,0,0);
text(boost_max,60,160,24);
for (int j=0; j <= 4; j++)
{
boost_max[j]=input[j+1];
}
stroke(255,0,0);
text(boost_max,60,160,24);
delay(10);
}
}
Thanks in advance for any assistance...