5 years ago.

I am trying to convert the arduino code into mbed code so can anyone help me with this code?

  1. include<SoftwareSerial.h> SoftwareSerial Myserial(11,12); char command='D'; int trig1=2; int echo1=5;

long dur1; int d1; void setup() { put your setup code here, to run once: pinMode(trig1, OUTPUT); pinMode(echo1, INPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT); pinMode(10,OUTPUT); Myserial.begin(9600); Serial.begin(9600); pinMode(13,OUTPUT);} void loop() { digitalWrite(trig1, LOW); delayMicroseconds(2); digitalWrite(trig1, HIGH); delayMicroseconds(10); digitalWrite(trig1, LOW); dur1 = pulseIn(echo1, HIGH); delayMicroseconds(2); d1= dur1*0.034/2; if(Myserial.available()>0) { command=Myserial.read(); }

if(d1>10) { digitalWrite(13,LOW);

Serial.println(command); switch(command) { case 'R': digitalWrite(7,HIGH); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,HIGH); break; case 'S': digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,LOW); break; case 'B': digitalWrite(7,LOW); digitalWrite(8,HIGH); digitalWrite(9,LOW); digitalWrite(10,HIGH); break; case 'F': digitalWrite(7,HIGH); digitalWrite(8,LOW); digitalWrite(9,HIGH ); digitalWrite(10,LOW); break; case 'L': digitalWrite(7,LOW); digitalWrite(8,HIGH); digitalWrite(9,HIGH); digitalWrite(10,LOW); break; } } else { digitalWrite(13,HIGH); digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,LOW); delay(2000); switch(command) { case 'R': digitalWrite(7,HIGH); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,HIGH); break; case 'S': digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(10,LOW); break; case 'B': digitalWrite(7,LOW); digitalWrite(8,HIGH); digitalWrite(9,LOW); digitalWrite(10,HIGH); break; case 'F': digitalWrite(7,HIGH); digitalWrite(8,LOW); digitalWrite(9,HIGH ); digitalWrite(10,LOW); break; case 'L': digitalWrite(7,LOW); digitalWrite(8,HIGH); digitalWrite(9,HIGH); digitalWrite(10,LOW); break; } }

}

1 Answer

5 years ago.

1) In the future please post your code using

<<code>>
code here
<</code>>

So that it is formatted in a readable way.

2) Please make an attempt at doing it yourself and then ask if you get stuck rather than just posting the arduino code and expecting someone else to do everything for you.

You need to define a set of DigitalOuts and then change the calls to DigitalWrite to setting those pins. Take a look at the blink sample code for examples of how to do this.