Toggle LED behaviour using the select button

This commit is contained in:
Kristian Sloth Lauszus 2016-03-21 18:21:12 +01:00
parent 92e24534e5
commit 400f9c0dcf

View file

@ -28,33 +28,34 @@ void loop() {
Usb.Task(); Usb.Task();
if (srw1.connected()) { if (srw1.connected()) {
#if 0 // Set to 1 in order to show a crazy strobe light effect if (printTilt) { // Show tilt angle using the LEDs
static uint32_t timer; srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value
if (millis() - timer > 12) { Serial.println(srw1.srws1Data.tilt);
timer = millis(); // Reset timer } else { // Show strobe light effect
static uint32_t timer;
if (millis() - timer > 12) {
timer = millis(); // Reset timer
static uint16_t leds = 0; static uint16_t leds = 0;
//PrintHex<uint16_t > (leds, 0x80); Serial.println(); //PrintHex<uint16_t > (leds, 0x80); Serial.println();
srw1.setLeds(leds); // Update LEDs srw1.setLeds(leds); // Update LEDs
static bool dirUp = true; static bool dirUp = true;
if (dirUp) { if (dirUp) {
leds <<= 1; leds <<= 1;
if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs
dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction
else if (!(leds & 0x8000)) // If last bit is not set, then set the lowest bit else if (!(leds & 0x8000)) // If last bit is not set, then set the lowest bit
leds |= 1; // Set lowest bit leds |= 1; // Set lowest bit
} else { } else {
leds >>= 1; leds >>= 1;
if (leds == 0) // Check if all LEDs are off if (leds == 0) // Check if all LEDs are off
dirUp = true; // If all LEDs are off, then repeat the sequence dirUp = true; // If all LEDs are off, then repeat the sequence
else if (!(leds & 0x1)) // If last bit is not set, then set the top bit else if (!(leds & 0x1)) // If last bit is not set, then set the top bit
leds |= 1 << 15; // Set top bit leds |= 1 << 15; // Set top bit
}
} }
} }
#else
srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value
#endif
if (srw1.srws1Data.leftTrigger) { if (srw1.srws1Data.leftTrigger) {
Serial.print(F("L2: ")); Serial.print(F("L2: "));
@ -68,7 +69,7 @@ void loop() {
if (srw1.buttonClickState.select) { if (srw1.buttonClickState.select) {
srw1.buttonClickState.select = 0; // Clear event srw1.buttonClickState.select = 0; // Clear event
Serial.println(F("Select")); Serial.println(F("Select"));
printTilt = !printTilt; // Print tilt value printTilt = !printTilt; // Print tilt value & show it using the LEDs as well
} }
if (srw1.buttonClickState.back) { if (srw1.buttonClickState.back) {
@ -174,9 +175,6 @@ void loop() {
Serial.println(); Serial.println();
break; break;
} }
if (printTilt)
Serial.println(srw1.srws1Data.tilt);
} }
} }