Buton ile DC motor hız kontrolü
// ardumoto shield kullanılmıştır.
// www.makersdukkan.com
const byte PWMA = 3;
const byte DIRA = 12;
const int buton_1 = 6; // buton_1 6 nolu pine takılacak
const int buton_2 = 7; // buton_2 7 nolu pine takılacak
int hiz=5; // 255 maksimum değer
int buton1=1;
int buton2=1;
int yon=0; // 0 ise ileri, 1 ise geri
void setup()
{
pinMode(PWMA, OUTPUT);
pinMode(DIRA, OUTPUT);
pinMode(buton_1, INPUT);
pinMode(buton_2, INPUT);
digitalWrite(PWMA, LOW);
digitalWrite(DIRA, LOW);
}
void loop()
{
digitalWrite(DIRA,yon);
analogWrite(PWMA,hiz);
buton1 = digitalRead(buton_1);
buton2 = digitalRead(buton_2);
delay(5); // butona basınca oluşan arkı engellemek için
if (buton1==0) hiz=hiz+1; // buton1 e basılmışsa hızı 1 artacak
if (buton2==0) hiz=hiz-1; // buton2 ye basılmışsa hızı 1 azalacak
}