ช่วยทีครับ เกี่ยวกับ arduino Interrupt

Started by kabutokungzz, March 24, 2013, 01:25:36 PM

Previous topic - Next topic

kabutokungzz

พอดีผม งง เรื่อง Interrupt  น่ะครับ คือผมต้องหาให้กดปุ่ม เปลี่ยนฟังค์ชั่นไปเรื่อยๆ แต่มันไม่เปลี่ยนน่ะครับ พอดีมือใหม่ครับ

int trigger = A0;
const int rled = 11;
const int gled = 12;
const int bled = 13;

int colorStep = 0;
int dimmingTimer = 2;

void setup ()
{
pinMode (rled, OUTPUT);
pinMode (gled, OUTPUT);
pinMode (bled, OUTPUT);
attachInterrupt(trigger, bkb,  CHANGE);

}

void bkb()
{
colorStep = colorStep+1;
}

void loop()
{
if (colorStep > 4) colorStep = 0;
//////////////1//////////////////
if (colorStep == 1) //White
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
analogWrite(rled, fadeValue);
analogWrite(gled, fadeValue);
analogWrite(bled, fadeValue);
delay (dimmingTimer);
}
/////////////////2///////////////////////////
if (colorStep == 2) //Red
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
analogWrite(rled, fadeValue);
delay (dimmingTimer);
}
///////////////////////3//////////////////////
if (colorStep == 3) //Green
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
analogWrite(gled, fadeValue);
delay (dimmingTimer);
}
////////////////////////4//////////////////////////
if (colorStep == 4) //Blue
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
analogWrite(bled, fadeValue);
delay (dimmingTimer);
}
}

pacozaa

http://arduino.cc/en/Reference/AttachInterrupt

trigger กำหนดถูกไหมครับ ลองดูจากลิงค์นี้ครับ
กำหนดเป็น A0 ไม่ได้ครับ ลองดูนะครับ