Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What would the following code for arduino look like for the raspberry pi? I am new to programming and would like to know how they

What would the following code for arduino look like for the raspberry pi? I am new to programming and would like to know how they vary.

#include

#include

#define IN1 4 // Arduino pin 4 is connected to MDDS60 pin IN1.

#define BAUDRATE 9600

Cytron_SmartDriveDuo smartDriveDuo30(SERIAL_SIMPLFIED, IN1, BAUDRATE);

char inChar;

signed int speedLeft, speedRight;

void setup()

{

pinMode(13, OUTPUT);

Serial.begin(9600);

digitalWrite(13, HIGH);

delay(2000); // Delay for 5 seconds.

digitalWrite(13, LOW);

}

void loop()

{

if (Serial.available()) {

delay(100);

inChar = (char)Serial.read();

if (inChar == '0') {

digitalWrite(13, LOW);

speedLeft = 0;

}

else if (inChar == '1') {

digitalWrite(13, HIGH);

speedLeft = 50;

}

else if (inChar == '2') {

digitalWrite(13, HIGH);

speedLeft = 100;

}

else if (inChar == '3') {

digitalWrite(13, HIGH);

speedLeft = -50;

}

else if (inChar == '4') {

digitalWrite(13, HIGH);

speedLeft = -100;

}

else if (inChar == '5') {

digitalWrite(13, LOW);

speedRight = 0;

}

else if (inChar == '6') {

digitalWrite(13, HIGH);

speedRight = 50;

}

else if (inChar == '7') {

digitalWrite(13, HIGH);

speedRight = 100;

}

else if (inChar == '8') {

digitalWrite(13, HIGH);

speedRight = -50;

}

else if (inChar == '9') {

digitalWrite(13, HIGH);

speedRight = -100;

}

smartDriveDuo30.control(speedLeft, speedRight);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions