Changing Control Scheme to Serial Reading

This commit is contained in:
Tempest 2024-10-31 14:56:55 +07:00
parent a7cf62b9eb
commit 8b2a97b364

View File

@ -13,6 +13,8 @@ struct Button {
bool pressed;
};
struct Panel [led0,led1,led2,led3];
// Defining BOOT button on ESP32 as our built-in button.
Button button1 = {INTERRUPT_PIN, 0, false};
@ -209,25 +211,23 @@ void dmxSetup() {
Serial.print("Done");
// ...and then set the communication pins!
const int tx_pin = 18;
const int rx_pin = 5;
const int tx_pin = 23;
const int rx_pin = 22;
const int rts_pin = 21;
Serial.printf("\nSetting up pin %d as Transmit Pin, pin %d as Receive Pin and pin %d as RTS Pin... ", tx_pin, rx_pin, rts_pin);
dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin);
Serial.print("Done\n");
}
int serialRead(){
int incomingByte;
void serialRead(){
String incomingByte;
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
incomingByte = Serial.readStringUntil('\r\n');
Serial.print("\nI received: ");
Serial.print(incomingByte);
mode = incomingByte.toInt();
}
return incomingByte;
}
void setup() {
@ -247,11 +247,12 @@ void loop() {
// Preparing next packet
if (button1.pressed){
if (mode < modeAmount - 1){mode++;} else {mode = 0;};
Serial.printf("\n Changing to mode %d", mode); // Increment the value of each slot, excluding the start code.
Serial.printf("\nChanging to mode %d", mode); // Increment the value of each slot, excluding the start code.
button1.pressed = false; // Reset button status to FALSE
};
// Wait until the packet is finished being sent before proceeding.
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
// Now write the packet synchronously!
dmx_write(DMX_NUM_1, dataSeq[mode], 100);
serialRead();
}