Arduino program convert in MATLAB program?

2 views (last 30 days)
SK MD FAROQUE
SK MD FAROQUE on 9 Jun 2018
Edited: Walter Roberson on 29 Jun 2018
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
//HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key);
protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);
if (c)
OnKeyPressed(c);
}
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{
static uint32_t next_time = 0; //watchdog
static uint8_t current_cursor = 0; //tracks current cursor position
if( millis() > next_time ) {
lcd.clear();
current_cursor = 0;
delay( 5 ); //LCD-specific
lcd.setCursor( 0,0 );
}//if( millis() > next_time ...
next_time = millis() + 200; //reset watchdog
if( current_cursor++ == ( DISPLAY_WIDTH + 1 )) { //switch to second line if cursor outside the screen
lcd.setCursor( 0,1 );
}
Serial.println( (char)key );
lcd.print( (char)key );
};
KbdRptParser Prs;
void setup()
{
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay( 200 );
Hid.SetReportParser(0, (HIDReportParser*)&Prs);
// set up the LCD's number of columns and rows:
lcd.begin(DISPLAY_WIDTH, 2);
lcd.clear();
lcd.noAutoscroll();
lcd.print("Ready");
delay( 200 );
}
void loop()
{
Usb.Task();
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
delay(3);
}
This is my Arduini program I want to Convert to Matlab program anyone help?
  1 Comment
Walter Roberson
Walter Roberson on 9 Jun 2018
Are you asking how to convert it into MATLAB calls to writeDigitalPin() and so on, so that MATLAB would be in control and telling the Arduino what to do at each step?
Or are you wanting to write a program that does something similar, but using the Data Acquisition Toolbox to talk to some data acquisition card and to control motors, without involving any Arduino, such as for the case where even a higher end Arduino is too slow for your purposes?
Or are you asking how to modify this program so that MATLAB can start it up on an Arduino ?

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 9 Jun 2018
As far as converting your code, someone just has to go through it line by line converting to MATLAB syntax, and that might as well be you, right?

Madhu Govindarajan
Madhu Govindarajan on 29 Jun 2018
Edited: Walter Roberson on 29 Jun 2018
Is this the resource you are looking for?
If you create an add-on using this workflow, then there should be an equivalent to most of the Arduino functions from MATLAB and you can control the LCD.
If not, please post information about the actual sensor itself for others here to help.

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!