头盔程序。控制l298n的,用在MSP上,可以给arduino移植,改针脚就可以
#include<SoftwareSerial.h> #define input112 #define input2 13 #define input3 14 #define input4 19 int a ; int b; //int c; //int en=39; int p; int A; int B; int R; int sensorValue; SoftwareSerialmySerial(P2_1, P2_2); // RX, TX void setup() { mySerial.begin(9600); Serial.begin(9600); pinMode(input1,OUTPUT); pinMode(input2,OUTPUT); pinMode(input3,OUTPUT); pinMode(input4,OUTPUT); } void loop() { if (Serial.available() > 0) { p = Serial.parseInt(); while (Serial.read() == 'X') { if(p<5000) { int i=1; } else {if (p<11000) { B=p-10000; mySerial.println(A); } else { A=p-20000} } } } int pos = analogRead(A0); mySerial.print("A"); mySerial.println(A); a=A-pos; mySerial.print("a"); mySerial.println(a); if(a>15) { analogWrite(input1, 255); analogWrite(input2, 0); } else {if(a<-15) { analogWrite(input1, 0); analogWrite(input2, 255); } else { analogWrite(input1, 0); analogWrite(input2,0); } } int pos2 = analogRead(A3); b=B-pos2; if(b>12) { analogWrite(input3, 255); analogWrite(input4, 0); } else { if (b<-12) { analogWrite(input3, 0); analogWrite(input4, 255); } else { analogWrite(input3, 0); analogWrite(input4,0); } } sensorValue = analogRead(A5); sensorValue=map(sensorValue,30,250,45,75); sensorValue=-sensorValue*sensorValue*0.001746+0.3784*sensorValue+51.35; sensorValue=sensorValue+10000; Serial.print( sensorValue); Serial.print("F"); delay(100); }
|