Hi im trying to learn how to use packet markers. in my last post Displaying radio stations on the Touchshield slide - #3 by system - Displays - Arduino Forum they to use packets but i have no clue what they are or how to use them. So i need help on how to use use them the these codes
Touchshield:
PImage timedis;
PImage menubut;
PImage batbar;
PImage arrowL;
PImage arrowR;
PImage volButt;
PImage button;
int volume;
char out[3];
unsigned int Xstore; //setup temporary variable
unsigned int Ystore; //setup temporary variable
void setup(){
Serial.begin(2400);
//open(FlashTransfer);
background(0);
arrowL = loadImage("arrowL.bmp");
arrowR = loadImage("arrowR.bmp");
volButt = loadImage("volButt.bmp");
timedis = loadImage("timedis.bmp");
menubut = loadImage("menubut.bmp");
batbar = loadImage("batbar.bmp");
button = loadImage("button.bmp");
image(timedis,260,0);
image(menubut,0,0);
stroke(100);
fill(100);
image(batbar,136,0);
rect(140,3,37,9);
triangle(50,135,70,120,70,150);
triangle(215,135,195,120,195,150);
noFill();
//rect(50,120,20,30);
//rect(195,120,20,30);
image(button,45,200);
image(button,110,200);
image(button,175,200);
image(volButt,275,105);
stroke(153);
text("VOL",276,90,15);
//text("15",287,170,11);
//text("7",292,90,11);
text("SEEK",110,90,15);
//text("94.5",110,135,15);
text("1",70,215,11);
text("2",135,215,11);
text("3",200,215,11);
text("+",293,126,15);
text("-",293,218,15);
}
void loop(){
gettouch();
if(mouseX != Xstore || mouseY != Ystore){
if(mouseX > 45 & mouseX < 95 & mouseY > 200 & mouseY < 230){
Serial.print('a');
stroke(0,170,80);
text("1",70,215,11);
stroke(153);
text("2",135,215,11);
text("3",200,215,11);
stroke(0);
fill(0);
rect(75,120,115,30);
stroke(153);
//dtostrf(channel,2,0,out);
//text(out,120,135,15);
}
else if(mouseX > 110 & mouseX < 160 & mouseY > 200 & mouseY < 230){
Serial.print('b');
stroke(0,170,80);
text("2",135,215,11);
stroke(153);
text("1",70,215,11);
text("3",200,215,11);
stroke(0);
fill(0);
rect(75,120,115,30);
stroke(153);
//dtostrf(channel,2,0,out);
//text(out,120,135,15);
}
else if(mouseX > 175 & mouseX < 225 & mouseY > 200 & mouseY < 230){
Serial.print('c');
stroke(0,170,80);
text("3",200,215,11);
stroke(153);
text("1",70,215,11);
text("2",135,215,11);
stroke(0);
fill(0);
rect(75,120,115,30);
stroke(153);
//dtostrf(channel,2,0,out);
//text(out,120,135,15);
}
if(mouseX > 195 & mouseX < 215 & mouseY > 120 & mouseY < 150){
Serial.print('u');
stroke(153);
text("1",70,215,11);
text("2",135,215,11);
text("3",200,215,11);
stroke(0,170,80);
fill(0,170,80);
triangle(215,135,195,120,195,150);
delay(100);
stroke(100);
fill(100);
triangle(215,135,195,120,195,150);
stroke(0);
fill(0);
rect(75,120,115,30);
stroke(153);
//dtostrf(channel,2,0,out);
//text(out,120,135,15);
}
if(mouseX > 50 & mouseX < 70 & mouseY > 120 & mouseY < 150){
Serial.print('d');
stroke(153);
text("1",70,215,11);
text("2",135,215,11);
text("3",200,215,11);
stroke(0,170,80);
fill(0,170,80);
triangle(50,135,70,120,70,150);
delay(100);
stroke(100);
fill(100);
triangle(50,135,70,120,70,150);
stroke(0);
fill(0);
rect(75,120,115,30);
stroke(153);
//dtostrf(channel,2,0,out);
//text(out,120,135,15);
}
if(mouseX > 280 & mouseX < 306 & mouseY > 119 & mouseY < 159){
Serial.print('+');
stroke(0,170,80);
text("+",293,126,15);
delay(100);
stroke(0);
fill(0);
rect(280,160,26,17);
volume++;
stroke(153);
text("+",293,126,15);
}
if(mouseX > 280 & mouseX < 306 & mouseY > 180 & mouseY < 225){
Serial.print('-');
stroke(0,170,80);
text("-",293,218,15);
delay(100);
stroke(0);
fill(0);
rect(280,160,26,17);
volume--;
stroke(153);
text("-",293,218,15);
}
Xstore = mouseX;
Ystore = mouseY;
}
if(volume >= 15){
volume=15;
}
if(volume <= 0){
volume=0;
}
if(volume < 10){
dtostrf(volume,2,0,out);
text(out,281,170,11);
}else{
dtostrf(volume,2,0,out);
text(out,287,170,11);
}
char charIn = 0;
byte i = 0;
char stringIn[32] = "";
while(Serial.available()){
charIn = Serial.read();
stringIn[i] = charIn;
i += 1;
}
// Clear screen and display the serial buffer as text
if (stringIn[0]){
fill(0);
stroke(0);
rect(75,120,115,30);
stroke(153);
text(stringIn,120,135,15);
}
}
Arduino:
#include <Si4703_Breakout.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#define RXpin 3
#define TXpin 2
char radByte;
int resetPin = 7;
int SDIO = A4;
int SCLK = A5;
Si4703_Breakout radio(resetPin, SDIO, SCLK);
int channel;
int volume;
char rdsBuffer[10];
SoftwareSerial touchSerial = SoftwareSerial(RXpin, TXpin);
void setup()
{
touchSerial.begin(2400);
/*Serial.println("\n\nSi4703_Breakout Test Sketch");
Serial.println("===========================");
Serial.println("a b Favourite stations");
Serial.println("+ - Volume (max 15)");
Serial.println("u d Seek up / down");
Serial.println("r Listen for RDS Data (15 sec timeout)");
Serial.println("Send me a command letter.");*/
radio.powerOn();
radio.setVolume(0);
}
void loop(){
radByte = touchSerial.read();
if (radByte == 'u')
{
channel = radio.seekUp();
displayStation();
}
else if (radByte == 'd')
{
channel = radio.seekDown();
displayStation();
}
else if (radByte == '+')
{
volume ++;
if (volume == 16) volume = 15;
radio.setVolume(volume);
}
else if (radByte == '-')
{
volume --;
if (volume < 0) volume = 0;
radio.setVolume(volume);
}
else if (radByte == 'a')
{
channel = 945; // Jamn 94.5 FM
radio.setChannel(channel);
displayStation();
}
else if (radByte == 'b')
{
channel = 969; //
radio.setChannel(channel);
displayStation();
}
else if (radByte == 'c')
{
channel = 1033; //
radio.setChannel(channel);
displayStation();
}
}
void displayStation(){
touchSerial.print(channel);
delay(1000);
}
ps. the touchshield and arduino are coded seperatly