Merhaba. Tinkercad'da bir projem var bu projede L293D ve 2 buton kullanarak DC motorun yönünü kontrol edebiliyorum. Fakat potansiyometreyi bir türlü ekleyemedim bu devreye nasıl potansiyometre ekleyebilirim? Koduda atarsanız sevinirim.
Siteye giremeyenler için fotoğraf attım.
Login - Tinkercad
www.tinkercad.com
Siteye giremeyenler için fotoğraf attım.
Kod:
#include <Keypad.h>
int motorPin1 = 5;
int motorPin2 = 6;
int motorSpeed = 0;
int potPin = A0;
const byte ROWS = 2;
const byte COLS = 1;
char hexaKeys[ROWS][COLS] = {{'2'}, {'1'}};
byte rowPins[ROWS] = {3, 2};
byte colPins[COLS] = {4};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
}
void loop()
{
char customKey = customKeypad.getKey();
switch (customKey)
{
case '1':
Serial.println("Rotates To Left");
rotateLeft();
break;
case '2':
Serial.println("Rotates To Right");
rotateRight();
break;
int motorSpeed = 0;
motorSpeed = map(potValue, 0, 1023, 0, 255);
}
int potValue = analogRead(potPin);
motorSpeed = map(potValue, 0, 1023, 0, 255);
analogWrite(motorPin1, motorSpeed);
analogWrite(motorPin2, motorSpeed);
}
void rotateLeft()
{
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}
void rotateRight(){
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin1, LOW);
}
Son düzenleyen: Moderatör: