Remove unneeded delays, rewrite main loop in example

This commit is contained in:
Aran Vink 2021-03-28 00:32:57 +01:00
parent 4f74db45f0
commit 425ae4584c
2 changed files with 29 additions and 25 deletions

View file

@ -218,8 +218,6 @@ void AMBX::Light_Command(uint8_t *data, uint16_t nbytes) {
Notify(PSTR("\r\nLight command "), 0x80); Notify(PSTR("\r\nLight command "), 0x80);
#endif #endif
pUsb->outTransfer(bAddress, epInfo[ AMBX_OUTPUT_PIPE ].epAddr, nbytes, data); pUsb->outTransfer(bAddress, epInfo[ AMBX_OUTPUT_PIPE ].epAddr, nbytes, data);
//Do really short delay, I've noticed otherwise the controller will receive all command at once, and might not process all of them.
delay(1);
} }
void AMBX::setLight(uint8_t ambx_light, uint8_t r, uint8_t g, uint8_t b) { void AMBX::setLight(uint8_t ambx_light, uint8_t r, uint8_t g, uint8_t b) {

View file

@ -13,8 +13,9 @@
USB Usb; USB Usb;
AMBX AMBX(&Usb); // This will just create the instance AMBX AMBX(&Usb); // This will just create the instance
bool printAngle;
uint8_t state = 0; uint8_t state = 0;
const long interval = 1000;
unsigned long previousMillis = 0;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -27,29 +28,34 @@ void setup() {
} }
Serial.print(F("\r\nAMBX USB Library Started")); Serial.print(F("\r\nAMBX USB Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
if (AMBX.AMBXConnected) { if (AMBX.AMBXConnected) {
if (state == 0) { unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
} else if (state == 1) { previousMillis = currentMillis;
AMBX.setAllLights(Red);
} else if (state == 2) { if (state > 4) {
AMBX.setAllLights(Green); state = 0;
} else if (state == 3) { }
AMBX.setAllLights(Blue); if (state == 0) {
} else if (state == 4) { Serial.print(F("\r\nRed"));
AMBX.setAllLights(White); AMBX.setAllLights(Red);
} else if (state == 1) {
Serial.print(F("\r\nGreen"));
AMBX.setAllLights(Green);
} else if (state == 2) {
Serial.print(F("\r\nBlue"));
AMBX.setAllLights(Blue);
} else if (state == 3) {
Serial.print(F("\r\nWhite"));
AMBX.setAllLights(White);
}
state++;
}
} }
//Example using single light:
//Example using single light: //AMBX.setLight(Wallwasher_center, White);
//AMBX.setLight(Wallwasher_center, White);
state++;
if (state > 4)
state = 0;
delay(1000);
}
delay(10);
} }