// LET THE WILD RUMPUS BEGIN =============================
void loop() {
  	if (Serial.available() > 0) {
		// read the incoming byte:
		incomingByte = Serial.read();

		// say what you got:
		Serial.print("I received: ");
		Serial.println(incomingByte, DEC);
                if ( incomingByte == 116 ) {
                  digitalWrite(ledPin, HIGH);   // sets the LED on
                  delay(1000);                  // waits for a second
                  digitalWrite(ledPin, LOW);    // sets the LED off
                  playMelody( melody_mario, beats_mario, sizeof(melody_mario) / 2 );
                }
                else if ( incomingByte == 112 ) {
                  digitalWrite(ledPin, HIGH);   // sets the LED on
                  delay(1000);                  // waits for a second
                  digitalWrite(ledPin, LOW);    // sets the LED off
                  playMelody( melody_gadget, beats_gadget, sizeof(melody_gadget) / 2 );
                }
				else if ( incomingByte == 99 ) {
                  //digitalWrite(ledPin, HIGH);   // sets the LED on
                  //delay(1000);                  // waits for a second
                  digitalWrite(ledPin, LOW);    // sets the LED off
                  playMelody( melody_mario_coin, beats_mario_coin, sizeof(melody_mario_coin) / 2 );
                }
	}


}
Example #2
0
void TtoolBar::setMelodyButtonVisible(bool vis) {
	m_melButton->melodyAction()->setVisible(vis);
	m_melButton->button()->menu()->setDisabled(!vis);
#if defined (Q_OS_ANDROID)
  playMelody()->setVisible(vis); // This way Android menu skips those actions when not visible
  recordMelody()->setVisible(vis);
  generateMelody()->setVisible(vis);
  if (vis) {
      flyActions()->insert(0, recordMelody()); // 'pitch detection' is first so insert other actions before
      flyActions()->insert(0, playMelody());
  } else {
      flyActions()->removeOne(playMelody());
      flyActions()->removeOne(recordMelody());
  }
#endif
}
Example #3
0
void RobotControl::beep(int beep_length){
  char scr1[]="8F";
  char scr2[]="8Fe";
  char scr3[]="1F";

  switch (beep_length)
  {
  case BEEP_SIMPLE:
  default:
    playMelody(scr1);
    break;

  case BEEP_DOUBLE:
	playMelody(scr2);
    break;

  case BEEP_LONG:
    playMelody(scr3);
  }

}
Example #4
0
int main() {
	char buf[BUFFERLENGTH];

	DDRD = (1 << LED_RED) | (1 << POWER_ON_INT) | (1 << LED_GREEN);
	DDRB = (1 << POWER_ON_EXT);
	PORTB = 0;
	PORTD = 0;

	PORTD |= (1 << TASTER); // pollup taster
	PORTD &= ~(1 << POWER_ON_EXT);
	PORTD &= ~(1 << POWER_ON_INT);

	// init values
	beepTime = 255;
	timeoutState4 = 0;
	uExtern = 0;
	uIntern = 0;
	time = 0;

	// init pwm
	DDRB |= (1 << PB2);
	OCR1A = 50; // PWM einstellen, bevor der Timer startet
	ICR1 = 10000; // TOP-wert
	OCR1B = ICR1 / 2;
	OCR1B = 0;

	TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11); // 2-Kanal "non-inverting"
	TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11); //Fastpwm, mit ICR1 als TOP

	//timer0
	TCCR0 = (1 << CS02) | (1 << CS00); // 1/1024
	TIMSK |= 1 << TOIE0;

	//timer2
	TCCR2 = (1 << CS22) | (1 << CS21) | (1 << CS20); // 1/1024
	TIMSK |= (1 << TOIE2);

	//uart
	uart_init(UART_BAUD_SELECT(9600, F_CPU));
	uart_puts("\n\nCN Power Switch V1.0\n");
	sei();

	//init adc
	ADMUX = (1 << REFS0);//aref = 5V (channel 0)
	ADCSRA = (1 << ADEN) | (1 << ADPS0) | (1 << ADPS1) | (1 << ADPS2) | (1 << ADFR) | (1 << ADIE) | (1 << ADSC); // free running, irq



	while (1) {
//		uIntern = getVoltageBattery();
//		uExtern = getVoltageExtern();
//		taster = isTaster0();

		sprintf(buf, "state: %01d extern %04d intern %04d\n", state, (int) uExtern, (int) uIntern);
		uart_puts(buf);

		if (state == 0) {
			if (uExtern > UEXTERNMIN) {
				state = 3;
			} else if (uIntern > UINTERNMIN) {
				state = 1;
			}
		} else if (state == 1) {
			LED_GREEN_ON
			LED_RED_OFF
			POWER_ON_EXT_OFF
			POWER_ON_INT_ON
			timeoutState4 = 255; //timer off

			if (uExtern > UEXTERNMIN) {
				state = 2;
			} else if (uIntern < UINTERNMIN) {
				state = 6;
			}
		} else if (state == 2) {
			LED_GREEN_OFF
			LED_RED_OFF
			POWER_ON_INT_OFF
			POWER_ON_EXT_ON

			if (taster && uIntern > UINTERNMIN) {
				state = 4;
				playMelody(melody4);
				timeoutState4 = 100;
			} else if (uIntern < UINTERNCRITICAL) {
				state = 3;
				playMelody(melody1);
			}
		} else if (state == 3) {