And to add to things...
Im trying to get it to work with a momentary button.
Using this tutorial
And changing the output to either the POT_PIN och MOTOR_PIN but i´m getting some strange results...
const int buttonPin = 2;
/* Include the library */
#include "HCMotor.h"
/* Set the pin that will control the motor. Note that it doesn't have to be a PWM pin -
any digital pin will do! */
#define MOTOR_PIN 7
/* Set the analogue pin the potentiometer will be connected to. */
#define POT_PIN A0
/* Create an instance of the library */
HCMotor HCMotor;
int buttonState = 0;
void setup()
{
/* Initialise the library */
HCMotor.Init();
/* Attach motor 0 to digital pin 7. The first parameter specifies the
motor number, the second is the motor type, and the third is the
digital pin that will control the motor */
HCMotor.attach(0, DCMOTOR, MOTOR_PIN);
/* Set the duty cycle of the PWM signal in 100uS increments.
Here 100 x 100uS = 1mS duty cycle. */
HCMotor.DutyCycle(0, 100);
pinMode(POT_PIN, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
int Speed;
/* Read the analogue pin to determine the position of the pot. The map
function takes this value which could be anywhere between 0 - 1024
and reduces it down to match the duty cycle range of 0 - 100 */
Speed = map(analogRead(POT_PIN), 0, 1024, 0, 100);
/* Set the on time of the duty cycle to match the position of the pot. */
HCMotor.OnTime(0, Speed);
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(POT_PIN, HIGH);
} else {
// turn LED off:
digitalWrite(POT_PIN, LOW);
}
}