Do my Indexes match my Code? (Bluetooth classic)

Do you have an option to turn your blocks into English too?

Export your .aia file and upload it here.
export_and_upload_aia

Your code that transmits:

Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));

I see three parts to each message.

The declarations of those variables:
image

That's two numbers and a true/false variable.

Here's the corrected way to receive and split data from println():

I removed your item selection part, which asked for nonexistent item numbers (4,5)
and did not even guess right for which of the 3 items was in the right place.

I suggest you sit down and have a conversation with whoever wrote the other part of this mismatched app pair.

2 Likes

OSI.export.aia (14.3 KB)

so the code matches now?

No.

It can be displayed, but it is up to you to match the subscripts.

You might actually have to even read your own code and the code of the other person.

And I have a question where "message_part_list" comes from ?

blocks (1)

But then the code is wrong at what point?

and do I need the <SoftwareSerial.h> library ?

Do you have reason to believe it would benefit you by removing it?

In fact, I use a shield base and therefore I have no specific port, moreover my BT is connected in grove on the shield base so I do not know...

Perhaps start from the question

Did a message arrive at my app?

What did it look like?

avrdude: ser_open(): can't set com-state for "\.\COM4"
Here is the error it gives me when I want to transmit the program to the arduino (I removed the library)

Try to narrow the error down: run another program on the board. If the problem persists, it's not the program that's causing the issue.

It's from my program now, but where can it come from?
I've been looking for 2 days but I can't find it...

avrdude: ser_open(): can't set com-state for ".\COM4"

this is a problem with the connection, not with the Sketch code.
Plug into another USB port, correctly set the port in the Arduino IDE, correctly load the Arduino driver...

This code is not finished, but you can study it...

BTabc.aia (14.4 KB)


#include <SoftwareSerial.h>

#define rxPin 11 // Pin 11 as RX, connected to TX of HC-05
#define txPin 10 // Pin 10 as TX, connected to RX of HC-05

SoftwareSerial mySerial(10,11);

int player1 = 0;
int turnNumber = 1;
int maxTurns = 100;
bool endGame = false;

// TARGET1
int ledTarget1 = 2;
int switchTarget1 = A0;

long previousMillisTarget1 = 0;
long intervalTarget1 = 1000;
bool isTargetHit1 = false;
// END TARGET1

void setup() {
Serial.begin(9600);
mySerial.begin(9600);
pinMode(ledTarget1, OUTPUT);
//pinMode(rxPin, INPUT);
//pinMode(txPin, OUTPUT);
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}

void loop() {
String customKey = "";

if (mySerial.available() > 0) {
customKey = mySerial.readString();
//customKey = mySerial.readStringUntil('\n');
Serial.println(customKey);
}

if (turnNumber == maxTurns) {
turnNumber = 1;
delay(1500);
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}

if (customKey == "service failed") {
turnNumber++;
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}

if (customKey == "start") {
endGame = false;
player1 = 0;
turnNumber = 1;
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
mySerial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}

checkTarget1();

}

void checkTarget1() {
int switchValue = analogRead(switchTarget1);

if (switchValue > 0 && !isTargetHit1) {
digitalWrite(ledTarget1, HIGH);
isTargetHit1 = true;
player1++;
turnNumber++;
Serial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
mySerial.println(String(player1) + "|" + String(turnNumber) + "|" + String(endGame));
}

unsigned long currentMillis = millis();

if (currentMillis - previousMillisTarget1 > intervalTarget1) {
previousMillisTarget1 = currentMillis;
isTargetHit1 = false;
digitalWrite(ledTarget1, LOW);
}
}

Hi, when I put the code, same error as before, I don't know where it can come from, if you could still help me really sorry

avrdude: ser_open(): can't set com-state for ".\COM4"
this is a problem with the connection

Try with driver ch341
http://kio4.com/arduino/1inicio.htm