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