Arduino Forum

Topics => Robotics => Topic started by: JACKSONSPARROW on Oct 08, 2018, 03:34 am

Title: Serial PORT with Arduino
Post by: JACKSONSPARROW on Oct 08, 2018, 03:34 am
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
Title: Re: Serial PORT with Arduino
Post by: AWOL on Oct 08, 2018, 10:47 am
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.
Title: Re: Serial PORT with Arduino
Post by: slipstick on Oct 08, 2018, 11:31 am
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 (http://forum.arduino.cc/index.php?topic=396450) for some ideas to get you started.

Steve