A
Arduino3y ago
dirt

help pls

//www.elegoo.com
//2016.12.09

// Arduino pin numbers
const int SW_pin = 48; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
const int mot1 = 52;
const int mot2 = 53;
const int mot1p2 = 50;
const int mot2p2 = 51;

void setup() {
pinMode(SW_pin, INPUT);
pinMode(mot1, INPUT);
pinMode(mot2, INPUT);
pinMode(mot1p2, INPUT);
pinMode(mot2p2, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}

void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(2000);
if ((analogRead(X_pin))> 505){
digitalWrite(mot1,HIGH);
digitalWrite(mot1p2,LOW);
}
}
//www.elegoo.com
//2016.12.09

// Arduino pin numbers
const int SW_pin = 48; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
const int mot1 = 52;
const int mot2 = 53;
const int mot1p2 = 50;
const int mot2p2 = 51;

void setup() {
pinMode(SW_pin, INPUT);
pinMode(mot1, INPUT);
pinMode(mot2, INPUT);
pinMode(mot1p2, INPUT);
pinMode(mot2p2, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}

void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(2000);
if ((analogRead(X_pin))> 505){
digitalWrite(mot1,HIGH);
digitalWrite(mot1p2,LOW);
}
}
i am confused why this dose not work
30 Replies
MaderDash
MaderDash3y ago
why are you trying to read digital pins?
dirt
dirtOP3y ago
joystick
MaderDash
MaderDash3y ago
no no Look at your code pleaase why are you trying to read digital pins?
dirt
dirtOP3y ago
oh sry
MaderDash
MaderDash3y ago
do you see one issue yet?
dirt
dirtOP3y ago
OH it was ther from the elegoo example
MaderDash
MaderDash3y ago
Ok so that is not correct. Im guessing this is a mega clone board correct?
dirt
dirtOP3y ago
yes mega
MaderDash
MaderDash3y ago
ok so read the first 5 lines of code there error is there.
dirt
dirtOP3y ago
ok
MaderDash
MaderDash3y ago
const int SW_pin = 48; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
const int mot1 = 52;
const int mot2 = 53;
const int mot1p2 = 50;
const int mot2p2 = 51;
const int SW_pin = 48; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
const int mot1 = 52;
const int mot2 = 53;
const int mot1p2 = 50;
const int mot2p2 = 51;
look closly and if you must write this down on paper some tims this helps you find the issue.
dirt
dirtOP3y ago
ok i am confuse i have no idea sory
MaderDash
MaderDash3y ago
do you see Xpin and Ypin?
dirt
dirtOP3y ago
yes
MaderDash
MaderDash3y ago
they are digital pins you can not nor ever read thenm as analog pins.
dirt
dirtOP3y ago
i mad it A0 and A1 but that did nothing
MaderDash
MaderDash3y ago
The issue is, NOW this brings your wireing into question. so a wireing diagram is now in order.
dirt
dirtOP3y ago
ok what do website do you sagest for the diagram
MaderDash
MaderDash3y ago
You can use wokwi, for a fast diagram and simulation. :d also Im in voice chat if you want to join
dirt
dirtOP3y ago
na i am good i do not talk to people that i do know know but thanks for the option,ther is no dc moter on wokwi i think
dirt
dirtOP3y ago
ok here is one pretend the servos is cd motors
No description
MaderDash
MaderDash3y ago
that looks correct.
AnonEngineering
are you using a motor driver?
dirt
dirtOP3y ago
not yet
AnonEngineering
'cuz pins won't power a DC motor
dirt
dirtOP3y ago
has for me befor
AnonEngineering
must be a very small motor, pins are rated for 20mA...
dirt
dirtOP3y ago
oh ok i will look in to one i will test on smaler moters then
AnonEngineering
not only current, you need to consider "back emf" when the motor stops it'll induce a large reverse voltage on the pin.
dirt
dirtOP3y ago
oh ok

Did you find this page helpful?