Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

msp430g2553:everything compiled fine, but the servo wont respond to the exe

$
0
0

ive compiled and uploaded my code (below) and when plug my msp430g2553 in it goes to the programmed angle it should when plugged in, but when i run the exe that is supposed to change its  angle it doesnt do anything. the exe is programmed to connect to com4, and the msp430 application uart is set to com4. i know the exe can detect it because it wont run unless it can, it just isnt responding. im am using energia 0101E0010 to compile and upload. any help would be appreciated.

 here is the code:

 

 

#include <Servo.h>

Servo myServo;

const int servoPin = 9; // the pin the servo is connected to

int val = 0;    // a value accumulated from data on the serial port
int angle = 90; // the current angle of the servo



void setup()
{
  Serial.begin(9600);
  myServo.attach(servoPin);
  myServo.write(angle);  // center the servo
}


void loop()
{
  if ( Serial.available())
  {
    char ch = Serial.read();

    if(ch >= '0' && ch <= '9')        // is ch a number?
   val = val * 10 + ch - '0';        // yes, accumulate the value
    else if(ch == '-') // is this the minus sign?
    {
   angle = angle - val;
   if(angle < 0)
      angle = 0;
   myServo.write(angle);      // write the new angle
   val = 0;
    }
    else if(ch == '+') // is this the plus sign?
    {
   angle = angle + val;
   if(angle > 180)
      angle = 180;
   myServo.write(angle);      // write the new angle
   val = 0;
    }
  }
}


Viewing all articles
Browse latest Browse all 2077

Trending Articles