Go Down

Topic: Serial PORT with Arduino (Read 199 times) previous topic - next topic

JACKSONSPARROW

So far i am able to control the speed of 1 OUTPUT connection to a motor,

now i would like to use many PWM OUTPUT pins and be able to have variations of motors on or off including LED lights, is this possible to do?

int input = 0;

void setup() {             
  // initialize the PWM pin #3 as an output.
  pinMode(3, OUTPUT);
  Serial.begin(9600);

  }

void loop() {
    input = Serial.read();
    if (input == '(0)'){
      analogWrite(3, 0);
      Serial.println("Speed is 0!");
   }
    if (input == '1'){
      analogWrite(3, 64);
      Serial.println("Speed is at 25%");
    }
    if (input == '2'){
      analogWrite(3, 127);
      Serial.println("Speed is at 50%");
   }
   if (input == '3'){
      analogWrite(3, 192);
      Serial.println("Speed is at 75%");
    }
    if (input == '4'){
      analogWrite(3,255);
      Serial.println("Speed is at 100%");
    }
}

MY Code so far

please bear with me as i am very new to Arduino i hope someone can offer me some advice and point me into the right direction.

thanks in advance

JACK

AWOL

#1
Oct 08, 2018, 10:47 am Last Edit: Oct 08, 2018, 10:47 am by AWOL
Code: [Select]
if (input == '(0)'){I don't have one of those on my keyboard, and I'm betting you don't either.

Please remember to use code tags when posting code.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

slipstick

To extend the code to control several different devices you'll need messages that contain something to tell you which device the information is intended for. Have a look at Serial Input Basics for some ideas to get you started.

Steve

Go Up