The code works, but in the LCD display I want to show speed and accleration on a imagnery car.
Right now it is just printed the values from the potmeter, and I want to make a code that print speed and accleration.
Do anyone have any ideas?
Greetings Eirik
/*
Stepper Motor Control - speed control-verdier skal vises på LCDdisplay
*/
#include <LiquidCrystal.h> // include the library code
#include <Stepper.h> // include the library code
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
Stepper myStepper(stepsPerRevolution, 6, 7, 8, 9); // initialize the stepper library on pins 6 through 9:
int stepCount = 0; // number of steps the motor has taken
int potPin1 = A0;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(potPin1, INPUT);
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(A0); // read the sensor value:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100); // map it to a range from 0 to 100:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed); // set the motor speed:
myStepper.step(stepsPerRevolution / 100); // step 1/100 of a revolution:
}
lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
lcd.print("Hastighet: "); // Prints Sensor Val: to LCD
lcd.print(motorSpeed); // Prints value on Potpin1 to LCD
lcd.setCursor(0, 1); // Sets the cursor to col 1 and row 0
lcd.print("Acc: "); // Prints Sensor Val: to LCD
lcd.print(motorSpeed); // Prints value on Potpin1 to LCD
Serial.println(sensorReading);
}