Code to:
output a value (dcSpeed) to a DC motor that is connected to digital pin 10 of the Arduino, keeping into consideration, that this pin should give a ‘pulse-width modulated’ (PWM) output that switches rapidly between +0V and +5V to give the effect of a voltage that can vary continuously between these values
No complete code. The function you're looking for is analogWrite.
so thats the function that needs to be used..what do you mean by theres no complete code?
preethi16:
so thats the function that needs to be used..what do you mean by theres no complete code?
That was a hint for you to write it yourself unless you think that someone else should do your assignment.
And just to give a heads up, the output of analogWrite should be used to feed a motor driver, and should not be connected directly to the motor.
Most motors pull much more current that the arduino pins can provide.
To output a value (dcSpeed) to a DC motor that is connected to digital pin 10 of the Arduino, keeping into consideration, that this pin should give a 'pulse-width modulated' (PWM) output that switches rapidly between +0V and +5V to give the effect of a voltage that can vary continuously between these values:
the code i got was:
// Connect the base of the transistor to pin 10.
// Even though it's not directly connected to the motor,
// we'll call it the 'motorPin'
const int motorPin = 10;
void setup()
{
pinMode(motorPin, OUTPUT); // set up the pin as an OUTPUT
Serial.begin(9600); // initialize Serial communications
}
void loop()
{ // This basically replicates a blink, but with the motorPin instead.
int onTime = 3000; // milliseconds to turn the motor on
int offTime = 3000; // milliseconds to turn the motor off
analogWrite(motorPin, 255); // turn the motor on (full speed)
delay(onTime); // delay for onTime milliseconds
analogWrite(motorPin, 0); // turn the motor off
delay(offTime); // delay for offTime milliseconds
}
Is this correct? Confused as to where the variable 'dcspeed' comes in the code though
It appears the variable dcspeed should have the values 0 or 255.
Please remember to use code tags when posting code.
i see.. but how should that be written in the code? like is it supposed to be written like:
int dcspeed = 0;
int dcspeed = 255;
?
Yes it could be written like that, though in code tags, but you'd need to be sure which instance of dcspeed was in scope.
(deleted)