Monday, December 8, 2014

Coding is good for you

int PWM_OUT = 9;
float duty = 0.0;
int onTime;
void setup()
{
  pinMode(PWM_OUT, OUTPUT);
  pinMode(13, OUTPUT);
}
 
void loop()
{
  onTime = floor(duty*50);
  digitalWrite(PWM_OUT, HIGH);
  digitalWrite(13, HIGH);
  delay(onTime);
  digitalWrite(PWM_OUT,LOW);
  digitalWrite(13, LOW);
  delay(50-onTime);


}​

*********************************************************************************
This code was written so that we could control the speed of the motor instead only disconnecting it and reconnecting it. I would also like to point out in the code is that a PWM had to be used in order for it to work properly. PWM stands for Pulse Width Modulation. This is how we control the motor itself. By varying the proportion of the duty cycle, it tells the motor how fast to spin and when to spin that fast. We are hoping that this could will help us when we trying to integrate the joystick into the project. 

No comments:

Post a Comment