Its getting messy as i have been commenting out bits trying to clear this fault, checksums are no longer used in this variant stuff like that but this is the full code:
//set up capacitive sensors
CapacitiveSensor cs_2_1 = CapacitiveSensor(2, 9); // 5M resistor between pins 2 & 9, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_2_2 = CapacitiveSensor(2, 11); // 5M resistor between pins 2 & 11, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor cs_2_3 = CapacitiveSensor(2, 13); // 5M resistor between pins 2 & 13, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor cs_2_4 = CapacitiveSensor(2, 15); // 5M resistor between pins 2 & 15, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor cs_2_5 = CapacitiveSensor(2, 17); // 5M resistor between pins 2 & 17, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor cs_2_6 = CapacitiveSensor(2, 8); // 5M resistor between pins 2 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor cs_2_7 = CapacitiveSensor(2, 7); // 5M resistor between pins 2 & 7, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor cs_2_8 = CapacitiveSensor(2, 6); // 5M resistor between pins 2 & 6, pin 8 is sensor pin, add a wire and or foil
//set button flags
bool But1Call = 0;
bool But2Call = 0;
bool But3Call = 0;
bool But4Call = 0;
bool But5Call = 0;
bool But6Call = 0;
bool But7Call = 0;
bool But8Call = 0;
//name outputs
int led1 = 10;
int led2 = 12;
int led3 = 14;
int led4 = 16;
int led5 = 18;
int buzz = 5;
int note = 3000; // buzzer tone
int splashDelay = 200;
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
//#############################################my data########################################
int iAm = 3; //this is device number 2 (0 = master 1 = computer p = eprom program incoming from computer)
float checkSum = 0.00; //check sum to send as serial
float voltage = 0.00; //system voltage
int data[20] {0, 0, 0, 0, 0, 0, 0, 0, 0}; //keypad output call
//#############################################data from master################################
int frm = 0;
int rsvp = 0; //response requested from unit
int out1 = 0; //output states from master
int out2 = 0; //output states from master
int out3 = 0; //output states from master
int out4 = 0; //output states from master
int out5 = 0; //output states from master
int alarm = 0; //alarm state
int test14 = 0;
String VString = ""; //master voltage
String ChecksumString = ""; //master checksum
float VFloat = 0;
float ChecksumFloat = 0;
float checkSumCalc = 0;
void setup()
{
Serial.begin(9600); //initialize serial
inputString.reserve(200); // reserve 200 bytes for the inputString:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
//####################################splash#############################
digitalWrite(led1, HIGH);
tone(buzz,1000);
delay(splashDelay);
digitalWrite(led2, HIGH);
tone(buzz,2000);
delay(splashDelay);
digitalWrite(led3, HIGH);
tone(buzz,3000);
delay(splashDelay);
digitalWrite(led4, HIGH);
tone(buzz,4000);
delay(splashDelay);
digitalWrite(led5, HIGH);
tone(buzz,5000);
delay(splashDelay);
digitalWrite(led5, LOW);
tone(buzz,4000);
delay(splashDelay);
digitalWrite(led4, LOW);
tone(buzz,3000);
delay(splashDelay);
digitalWrite(led3, LOW);
tone(buzz,200);
delay(splashDelay);
digitalWrite(led2, LOW);
tone(buzz,1000);
delay(splashDelay);
digitalWrite(led1, LOW);
noTone(buzz);
delay(splashDelay);
}
void loop()
{
long start = millis();
long total1 = cs_2_1.capacitiveSensor(30);
long total2 = cs_2_2.capacitiveSensor(30);
long total3 = cs_2_3.capacitiveSensor(30);
long total4 = cs_2_4.capacitiveSensor(30);
long total5 = cs_2_5.capacitiveSensor(30);
long total6 = cs_2_6.capacitiveSensor(30);
long total7 = cs_2_7.capacitiveSensor(30);
long total8 = cs_2_8.capacitiveSensor(30);
//##################################SET FLAGS#################
//Button 1 flag set
if (total1 > "4000") {
if (But1Call == 0){
But1Call = 1;
}
else {
But1Call = 0;
}
}
else {
But1Call = 0;
}
//Button 2 flag set
if (total2 > "4000") {
if (But2Call == 0){
But2Call = 1;
}
}
else {
But2Call = 0;
}
//Button 3 flag set
if (total3 > "4000") {
if (But3Call == 0){
But3Call = 1;
}
}
else {
But3Call = 0;
}
//Button 4 flag set
if (total4 > "4000") {
if (But4Call == 0){
But4Call = 1;
}
}
else {
But4Call = 0;
}
//Button 5 flag set
if (total5 > "4000") {
if (But5Call == 0){
But5Call = 1;
}
}
else {
But5Call = 0;
}
//Button 6 flag set
if (total6 > "4000") {
if (But6Call == 0){
But1Call = 0; // board fault button 6 triggers button 1
But6Call = 1;
}
}
else {
But6Call = 0;
}
//Button 7 flag set
if (total7 > "4000") {
if (But7Call == 0){
But7Call = 1;
}
}
else {
But7Call = 0;
}
//Button 8 flag set
if (total8 > "4000") {
if (But8Call == 0){
But8Call = 1;
}
}
else {
But8Call = 0;
}
//######################################Flag actions######################
if (But1Call == 1) {
data[1] = 1 ;
tone(buzz,note);
}
if (But2Call == 1) {
data[2] = 1 ;
tone(buzz,note);
}
if (But3Call == 1) {
data[3] = 1 ;
tone(buzz,note);
}
if (But4Call == 1) {
data[4] = 1 ;
tone(buzz,note);
}
if (But5Call == 1) {
data[5] = 1 ;
tone(buzz,note);
}
if (But6Call == 1) {
data[6] = 1 ;
tone(buzz,note);
}
if (But7Call == 1) {
data[7] = 1 ;
tone(buzz,note);
}
if (But8Call == 1) {
data[8] = 1 ;
tone(buzz,note);
}
//##################################if data recieved decode############################################
//string from master = frm,rsvp,out1,out2,out3,out4,out5,in1,in2,in3,in4,in5,alarm
if (stringComplete) {
digitalWrite(led2, HIGH);
frm = inputString.charAt(0);
rsvp = inputString.charAt(1);
out1 = inputString.charAt(2);
out2 = inputString.charAt(3);
out3 = inputString.charAt(4);
out4 = inputString.charAt(5);
out5 = inputString.charAt(6);
test14 = inputString.charAt(14);
Serial.print(inputString);
inputString = "";
stringComplete = false;
//if (test14== '9'){
// digitalWrite(led2, HIGH);
//}
//alarm = inputString.charAt(6);
//VString = inputString.charAt(7);
//VString = VString + inputString.charAt(8);
//VString = VString + inputString.charAt(9);
//VString = VString + inputString.charAt(10);
//VString = VString + inputString.charAt(11);
// frm = frm - 47;
// rsvp = rsvp - 47;
// out1 = out1 - 47;
// out2 = out2 - 47;
// out3 = out3 - 47;
// out4 = out4 - 47;
// out5 = out5 - 47;
// Serial.print(rsvp);
// clear the string:
inputString = "";
stringComplete = false;
//alarm = alarm -48;
// if (checkSumCalc > ChecksumFloat - 1 and checkSumCalc < ChecksumFloat + 1 ) {
// checkSumCalc = 0;
// ChecksumFloat = 0;
if (frm == 0){
// if (out1 == 1) {
// digitalWrite(led1, HIGH);
// }
// else{ digitalWrite(led1, LOW);
// }
//
// if (out2 == 1) {
// digitalWrite(led2, HIGH);
// }
// else{ digitalWrite(led2, LOW);
// }
//
// if (out3 == 1) {
// digitalWrite(led3, HIGH);
// }
// else{ digitalWrite(led3, LOW);
// }
//
// if (out4 == 1) {
// digitalWrite(led4, HIGH);
// }
// else{ digitalWrite(led4, LOW);
// }
//
// if (out5 == 1) {
// digitalWrite(led5, HIGH);
// }
// else{ digitalWrite(led5, LOW);
// }
// if (alarm == 1) {
// tone(buzz, note);
// if (note >= 4000){
// note = 500;
// }
// else{
// note=note+500;
// }
//
// }
// else{ noTone(buzz);
// }
if (rsvp == iAm) {
// int InVoltage = analogRead(6); //INPUT VOLTAGE VALUE
// float voltage = InVoltage * (5.0/1023.0);
// voltage =voltage * 10; //voltage must be 2 digit)
// checkSum = voltage * (iAm + data[0] + data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + data[8] + data[9]);
digitalWrite(led3, HIGH);
Serial.print(iAm);
Serial.print(data[1]);
Serial.print(data[2]);
Serial.print(data[3]);
Serial.print(data[4]);
Serial.print(data[5]);
Serial.print(data[6]);
Serial.print(data[7]);
Serial.print(data[8]);
Serial.print(data[9]);
//Serial.print(voltage);
//Serial.println(checkSum);
noTone(buzz);
}
// clear the string:
inputString = "";
stringComplete = false;
}
else {
inputString = "";
rsvp = "";
//rsvp1 = "";
stringComplete = false;
}
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == 13 ) {
stringComplete = true;
digitalWrite(led1, HIGH);
}
}
}```