📜 ⬆️ ⬇️

Weekend Project: Imperial March on Servos and MSP430

Okay. It all started with the fact that I ordered servos. I thought it was one big, but it turned out that 5, but small. They did not pull the cargo I needed, but since there is something in the bins of the motherland, it means that something needs to be applied.



At first I wanted to make a clock in them in the opposite direction, but I was mistaken in the delays and got the sound “---”, which seemed interesting to me.
Next was the weekend and slow picking in the code, which has undergone several changes, was lost and rewritten for MSP430 and Wiring instead of BASCOM (because I was more lazy typing the program a second time, rather than writing it in another language), and eventually it looked like
CAUTION! Bydlokod!

#include <Servo.h> //  Servo myservo1;//  Servo myservo2; int x = 0; //  int y = 0; int z = 0; int w = 0; int g = 0; int h = 0; int q = 0; void setup() { myservo1.attach(7, 600, 800); //    (   )  myservo2.attach(8, 600, 800); myservo1.write(0); //   myservo2.write(0); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(RED_LED, OUTPUT); digitalWrite(GREEN_LED, LOW); digitalWrite(RED_LED, LOW); } void loop() { delay(2000);//   2 ,     q=song(80,40,0);//  q=song(80,40,0);// : q=song(-80,40,0);//  -   ,   ,      180    0 q=song(-50,30,-50);// -  .  -   30   30      q=song(-5,15,0); // -    ,      . q=song(-80,20,0); q=song(-10,10,-10); q=song(-10,10,0); q=song(-100,70,0); q=song(-80,32,-80); q=song(-40,32,-80); q=song(-80,32,-80); q=song(-70,32,0); q=song(-10,10,0); q=song(-100,20,-80); q=song(-70,40,0); q=song(-10,10,0); q=song(-100,20,-80); q=song(-70,40,0); q=song(-10,10,0); q=song(-100,50,0); q=song(-80,32,-80); q=song(-40,32,0); q=song(-10,10,0); q=song(-80,32,-80); q=song(-40,32,0); q=song(-10,10,0); q=song(-80,32,-80); q=song(-40,40,-40); q=song(-10,10,0); q=song(-10,8,-10); q=song(-10,8,-10); q=song(-10,32,-10); delay(2000000); } int song(int y, int z, int g){ x=x+y; //      h=h+g;//     w=(abs(y)*3.75+z*10/1.6)/2;//  .   ,       ,        if (g != 0) //      ? { myservo2.write(h); digitalWrite(GREEN_LED, HIGH); myservo1.write(x); digitalWrite(RED_LED, HIGH); } else { myservo1.write(x); digitalWrite(RED_LED, HIGH); } g=0; delay(w);//  -     digitalWrite(GREEN_LED, LOW); digitalWrite(RED_LED, LOW); delay(w); } 

Photo to distract attention and dilute the text:

')
Since I didn’t manage to pick up by ear, I went to the trick - I downloaded the midi, opened it in the editor and measured the duration of the notes and pauses. Those notes, whose tone differed too much - voiced by the second servo, it has a different sound.
Another photo:

Since the servos are powered by the board stabilizer, the coefficients are designed for a voltage of 3v, and for longer, the duration of the pauses will vary due to an increase in the speed of movement.

And, finally, the most interesting is video.

Source: https://habr.com/ru/post/156455/


All Articles