int potipin = (A0);
byte lastpotiwert;
unsigned long currenttime;
unsigned long lasttime;
unsigned long lasttimepoti;
int vpoti;
byte potiwert;
byte lastSB[30];
byte SBL;
const int SERIAL_BUFFER_SIZE = 30; // die maximale Telegrammlänge
byte SB[SERIAL_BUFFER_SIZE];
void setup() {
pinMode( potipin, INPUT);
Serial.begin(57600);
}
void loop() {
currenttime = millis();
vpoti = analogRead(A0);
potiwert = vpoti/4;
if (potiwert != lastpotiwert)
{
if((currenttime -lasttimepoti) > 50){
for(int i = 0; i < 8; i++){
Serial.write(value [potiwert] [i]);
}
lasttimepoti= currenttime;
}
lastpotiwert = potiwert;
}
if(( currenttime -lasttime ) > 500){
for(int i = 0; i < 8; i++){
Serial.write(value [potiwert] [i]);
}
lasttime = currenttime ;
}
if (read_serial() )
{
if ( SB[0]==49 && SB[1]==1 && SB[2]==0 && SB[3]==0 && SB[4]==0 && SB[5]==1 && SB[6]==0 )
{
for ( int i = 0; i <( SBL-2 ) ; i++) {
Serial.write(SB[i]);
}
Serial.write(5);
Serial.write(13);
Serial.write(237); // 237 243 nicht fix
Serial.write(50);
}
int n = memcmp(lastSB, SB, 30);
if ( n != 0 )
{
pars_serial();
}
}
memcpy(lastSB, SB, 30);
}
bool read_serial() {
static byte index;
while (Serial.available() ) {
byte c = Serial.read();
if (c == 49) { // das Starzeichen
index = 0;
}
SB[index] = c;
index++;
SBL = index;
if (c == 50)
{
return true;
}
}
return false; // Endzeichen noch nicht erreicht
}
// Array bis zum Endzeichen als Dezimalwerte ausgeben
void pars_serial() {
for (int i = 0; i < SERIAL_BUFFER_SIZE; i++) {
Serial.write(SB[i]);
if (SB[i] == 50) {
return;
}
}
}