Jump to content
43oh

launchpad msp430FR2433 Ultrasonic sensor and servo project


Recommended Posts

Hey, so I'm trying to pass an arduino uno project to my launchpad msp430FR2433. I already programed the right pins for the servo and sensor and I succesfully uploaded the program to the board but I can't get it to work correctly. The only thing that it does is that puts the servo in position 0. is there a problem with programming or should I have an issue with the connections?? I'm also curious to know if the Launchpad supports both of these components such as arduino does.

This is my program: (I'm using energia)

#include <Servo.h> 
 
Servo servo1;   // create servo object to control a servo 
int Echo = 7;   // Ultrasonic sensor Echo pin 7 on board
int Trig = 6;   // Ultrasonic sensor Trig pin 6 on board


long distancia;
long duracion;


void setup() 

  servo1.attach(9);  // attaches the servo on pin 10 to the servo object 
   pinMode(Echo, OUTPUT);
   pinMode(Trig, INPUT);

 
void loop() {
  ultra();
  servo1.write(0);
  if(distancia <=5){
  servo1.write(90);
  delay(1000); 
  }
}

void ultra(){
  digitalWrite(Echo, LOW);
  delayMicroseconds(2);
  digitalWrite(Echo, HIGH);
  delayMicroseconds(10);
  digitalWrite(Echo, LOW);
  duracion = pulseIn(Trig, HIGH);
 
  distancia = duracion*0.034/2;
  }
 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...