Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int motorPin = 9;
- int buttonPin1 = 2;
- int buttonPin2 = 3;
- int variableSpeed = 0;
- void setup()
- {
- pinMode(motorPin, OUTPUT);
- pinMode(buttonPin1, INPUT);
- pinMode(buttonPin2, INPUT);
- Serial.begin(9600);
- }
- void loop ()
- {
- if(digitalRead(buttonPin2) == 1)
- {
- Serial.println("B1");
- motorSpeed(50);
- }
- else if (digitalRead(buttonPin1) == 1)
- {
- Serial.println("B2");
- motorSpeed (-50);
- }
- delay(100);
- analogWrite(motorPin, variableSpeed);
- }
- int motorSpeed (int motorspeed){
- variableSpeed = motorspeed + variableSpeed;
- if (variableSpeed > 255) {
- variableSpeed = 255;
- }
- else if (variableSpeed < 0) {
- variableSpeed = 0;
- }
- return variableSpeed;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement