พอดี ตั้งตัวแปรแล้ว i ที่ตั้งไว้ค่า มันไม่ออก
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
volatile int i=0;//initializing a integer for incrementing and decrementing duty ratio.
#define buttonPinUP 3
#define buttonPinDOWN 4
#define Modfet 5
void setup()
{
Serial.begin(9600);
pinMode(Modfet, OUTPUT);
pinMode(buttonPinUP, INPUT);
pinMode(buttonPinDOWN, INPUT);
}
void loop()
{
analogWrite(Modfet,i); // analogWrite values from 0 to 255
if (digitalRead(buttonPinUP)==LOW)
Serial.println("up");
{
if (i<255)
{
i++;//if pin up is pressed and the duty ratio value is less than 255
delay(30);
}
}
if (digitalRead(buttonPinDOWN)==LOW)
Serial.println("down");
{
if (i>0)
{
i--;// if pin down is pressed and the duty ratio value is greater than 0
delay(30);
}
}
}
ช่วยแก้ โค้ดหน่อยครับ
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
volatile int i=0;//initializing a integer for incrementing and decrementing duty ratio.
#define buttonPinUP 3
#define buttonPinDOWN 4
#define Modfet 5
void setup()
{
Serial.begin(9600);
pinMode(Modfet, OUTPUT);
pinMode(buttonPinUP, INPUT);
pinMode(buttonPinDOWN, INPUT);
}
void loop()
{
analogWrite(Modfet,i); // analogWrite values from 0 to 255
if (digitalRead(buttonPinUP)==LOW)
Serial.println("up");
{
if (i<255)
{
i++;//if pin up is pressed and the duty ratio value is less than 255
delay(30);
}
}
if (digitalRead(buttonPinDOWN)==LOW)
Serial.println("down");
{
if (i>0)
{
i--;// if pin down is pressed and the duty ratio value is greater than 0
delay(30);
}
}
}