void buzz(long duration, uint16_t freq) { if (freq > 0) { #if ENABLED(LCD_USE_I2C_BUZZER) lcd_buzz(duration, freq); #elif PIN_EXISTS(BEEPER) // on-board buzzers have no further condition SET_OUTPUT(BEEPER_PIN); #if ENABLED(SPEAKER) // a speaker needs a AC ore a pulsed DC //tone(BEEPER_PIN, freq, duration); // needs a PWMable pin unsigned int delay = 1000000 / freq / 2; int i = duration * freq / 1000; while (i--) { WRITE(BEEPER_PIN, HIGH); delayMicroseconds(delay); WRITE(BEEPER_PIN, LOW); delayMicroseconds(delay); } #else // buzzer has its own resonator - needs a DC WRITE(BEEPER_PIN, HIGH); delay(duration); WRITE(BEEPER_PIN, LOW); #endif #else delay(duration); #endif } else delay(duration); }
void buzz(long duration, uint16_t freq) { if (freq > 0) { #ifdef LCD_USE_I2C_BUZZER lcd_buzz(duration, freq); #elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition SET_OUTPUT(BEEPER); tone(BEEPER, freq); delay(duration); noTone(BEEPER); #else delay(duration); #endif } else { delay(duration); } }
void Task1() { uint8_t secret = 0; char* s = "Screen 1\\nWelcome!\\nScreen 2\\nDriver\\r\\nScreen 3\\n \\dTest\\d"; char* s_secret = "Congrats\\ndude\\nYou\\nfound it\\nSecret\\ncode!"; // Initialize FireFly LCD v1.2 board lcd_setup(); // Set LEDs lcd_led_set(1, 0); lcd_led_set(2, 0); lcd_led_set(3, 1); lcd_string_display_escape("FireFly\\nLCD v1.2"); lcd_wait_us(2000000); // Wait 2 seconds lcd_string_display_escape("Basic\\nLCD"); lcd_wait_us(2000000); // Wait 2 seconds lcd_string_display_escape("Driver\\nTest"); lcd_wait_us(2000000); // Wait 2 seconds // Load initial string array lcd_string_array_load(s); // Switch input loop while(1) { if(lcd_switch_pressed(1)) // If switch 1 is pressed { if(!secret) lcd_led_set(1, 1); // Set LED 1 // Buzz lcd_buzz(30); if(lcd_switch_pressed(2)) // If both switches are pressed { // Load new string array lcd_string_array_load(s_secret); // Set LEDs lcd_led_set(1, 1); lcd_led_set(2, 1); lcd_led_set(3, 1); secret = 1; } else { // Cycle string array lcd_string_array_cycle(); } } else if(lcd_switch_pressed(2)) // If switch 2 is pressed { if(!secret) lcd_led_set(2, 1); // Set LED 2 // Buzz lcd_buzz(30); // Reverse cycle string array lcd_string_array_cycle_reverse(); } else if(!secret) // If no switches pressed { lcd_led_set(1, 0); // Clear LED 1 lcd_led_set(2, 0); // Clear LED 2 } if(secret) { // Toggle LEDs lcd_led_toggle(1); lcd_led_toggle(2); lcd_led_toggle(3); } nrk_wait_until_next_period(); } }