Upgrade Kids-Car

Projecten die niet passen in bovenstaande onderwerpen
Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: Upgrade Kids-Car

Berichtdoor Koepel » 10 Dec 2017, 00:27

Mooi :D
Ik neem aan met die PWMservo library. Dat scheelt een hoop interrupts.

Advertisement

Berichten: 5
Geregistreerd: 02 Dec 2017, 02:02

Re: Upgrade Kids-Car

Berichtdoor Angel_D » 13 Dec 2017, 21:07

Nou eigenlijk nog niet eens.
Overigens gebruik de pedaal voor het aansturen van een servo, welke op zijn beurt de handbediening van een oma scootmobiel aanstuurt (trekt of duwt). Met de schakelaar ingedrukt rijd ik met dezelfde gaspedaal achteruit.
Project is overigens een kermis botsauto met een scoor mobiele elektrische aandrijving :-) :-)

Kijk zo ziet mijn code eruit:

#include <Servo.h>

Servo myservo; // Create servo object to control a servo
int buttonPin = 3; // Switch from forward to backward
int buttonState = 0; // variable for reading the pushbutton status
int potpin = A0; // Analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin


void setup() {
myservo.attach(9); // attaches the servo on pin 2 to the servo object
Serial.begin(9600); // Just for calibration and debug
pinMode(13, OUTPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);


if (buttonState == HIGH) // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
//Backward
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1000)
val = map(val, 0, 1023, 80, 0); // scale it to use it with the servo (value between 0 and 80)
myservo.write(val); // sets the servo position according to the scaled value
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // waits for the servo to get there
}
else
//Forward
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1000)
val = map(val, 0, 1023, 80, 160); // scale it to use it with the servo (value between 0 and 80)
myservo.write(val); // sets the servo position according to the scaled value
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(100); // waits for the servo to get there
}

//just for calibration and debug

int sensorValue = analogRead(potpin); // read the input on analog pin 0:
float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
Serial.print(sensorValue); // print out the ADC value you read:
Serial.print(" ");
Serial.print(voltage); // print out the voltage value you read:
Serial.print(" ");
Serial.println(val); // print out the servo value you read:
}

Vorige

Terug naar Overige projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 4 gasten