#include <pt.h>
static struct pt hilo4;
#define buton 2
#define tonePin 6
int t;
void setup()
{
PT_INIT(&hilo4);
pinMode(buton,INPUT);
pinMode(tonePin,OUTPUT);
}
void loop()
{
boton(&hilo4);
}
static int boton(struct pt *pt)
{
static long v = 0;
static int oldval = 0;
static int newval = 0;
PT_BEGIN(pt);
pinMode(buton,INPUT_PULLUP);
while(true)
{
newval = digitalRead(buton);
if(((newval^oldval)==1)&& newval == 0)
{
tone(tonePin, 195, 416.666666667);
delay(416.666666667);
tone(tonePin, 220, 416.666666667);
delay(416.666666667);
tone(tonePin, 233, 416.666666667);
delay(416.666666667);
tone(tonePin, 329, 208.333333333);
delay(208.333333333);
tone(tonePin, 293, 416.666666667);
delay(416.666666667);
tone(tonePin, 349, 1152.77777778);
delay(1152.77777778);
tone(tonePin, 195, 416.666666667);
delay(416.666666667);
tone(tonePin, 220, 416.666666667);
delay(416.666666667);
tone(tonePin, 233, 416.666666667);
delay(416.666666667);
tone(tonePin, 329, 208.333333333);
delay(208.333333333);
tone(tonePin, 293, 1666.66666667);
delay(1666.66666667);
delay(208.333333333);
tone(tonePin, 195, 416.666666667);
delay(416.666666667);
tone(tonePin, 220, 416.666666667);
delay(416.666666667);
tone(tonePin, 233, 416.666666667);
delay(416.666666667);
tone(tonePin, 329, 208.333333333);
delay(208.333333333);
tone(tonePin, 293, 416.666666667);
delay(416.666666667);
tone(tonePin, 349, 979.166666667);
delay(979.166666667);
delay(208.333333333);
tone(tonePin, 349, 416.666666667);
delay(416.666666667);
tone(tonePin, 293, 625.0);
delay(625.0);
tone(tonePin, 233, 208.333333333);
delay(208.333333333);
tone(tonePin, 220, 208.333333333);
delay(208.333333333);
tone(tonePin, 195, 833.333333333);
delay(833.333333333);
delay(208.333333333);
tone(tonePin, 146, 208.333333333);
delay(208.333333333);
tone(tonePin, 130, 208.333333333);
delay(208.333333333);
tone(tonePin, 146, 208.333333333);
delay(208.333333333);
tone(tonePin, 220, 2430.55555556);
delay(2430.55555556);
}
oldval=newval;
PT_YIELD(pt);
}
PT_END(pt);
}
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.