please anyone help me I need convert this code to matlab 🥺

3 views (last 30 days)
int analogPin = A0; int val = 0; int x = 0; #include TridentTD_LineNotify.h
#define SSID "jetusedtoiw" #define PASSWORD "12345678" #define LINE_TOKEN "qrQFE2XheIbfKk4IVSnpD9aL6noBZQGaj0diw4H0ufJ" String message = "ฝนตกแล้วน้า ระวังเป็นหวัดนะ!"; void setup() { Serial.begin(9600); Serial.println(LINE.getVersion());
WiFi.begin(SSID, PASSWORD);
Serial.printf("WiFi connecting to %s\n", SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(400);
}
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
LINE.setToken(LINE_TOKEN);
}
void loop() { val = analogRead(analogPin); Serial.print("val = "); Serial.println(val); if (val < 500 and x == 0) { LINE.notify(message); delay(1000); } if (val < 500) { x = 1; } else { x = 0; } delay(1000);

Accepted Answer

Edgar Guevara
Edgar Guevara on 3 Nov 2023
Have you tried Bing copilot?
It can give you a general outline to structure your code, like this:
% Assuming 'SSID' and 'PASSWORD' are defined
wifi = wifiConnect(SSID, PASSWORD);
disp(['WiFi connecting to ', SSID]);
while ~wifi.isConnected()
fprintf('.');
pause(0.4);
end
disp(' ');
disp('WiFi connected');
disp(['IP : ', wifi.localIP()]);
% Assuming 'LINE_TOKEN' is defined
LINE.setToken(LINE_TOKEN);
Of course, copilot would give you the following warning:
Please note that this is a simplified version and might not work as expected because MATLAB does not have built-in support for WiFi communication. You would need to use a MATLAB support package for Arduino or another hardware support package for WiFi communication. Also, the wifiConnect, isConnected, localIP, and setToken functions are placeholders for the actual functions you would use to connect to WiFi, check the connection status, get the local IP, and set the token for LINE respectively. You would need to replace these with the actual functions provided by your WiFi and LINE libraries.
I hope this helps! If you have any other questions, feel free to ask.
  3 Comments
Pongsatorn
Pongsatorn on 3 Nov 2023
int analogPin = A0; int val = 0; int x = 0; #include TridentTD_LineNotify.h
#define SSID "jetusedtoiw" #define PASSWORD "12345678" #define LINE_TOKEN "qrQFE2XheIbfKk4IVSnpD9aL6noBZQGaj0diw4H0ufJ" String message = "ฝนตกแล้วน้า ระวังเป็นหวัดนะ!"; void setup() { Serial.begin(9600); Serial.println(LINE.getVersion());
Pongsatorn
Pongsatorn on 3 Nov 2023
}
void loop() { val = analogRead(analogPin); Serial.print("val = "); Serial.println(val); if (val < 500 and x == 0) { LINE.notify(message); delay(1000); } if (val < 500) { x = 1; } else { x = 0; } delay(1000);

Sign in to comment.

More Answers (1)

MathWorks MATLAB Hardware Team
Hi,
Thanks for reaching out to us. You can use MATLAB Support Package for Arduino Hardware to try this workflow.
Here are the steps,
  1. Install Arduino Support Package, refer to this link to know more https://in.mathworks.com/help/supportpkg/arduinoio/ug/intro.html
  2. Configure Arduino over WiFi by following steps mentioned in this link, https://in.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html#bvn8wpb-1
  3. Use readVoltage API to read analog input voltage from an analog pin, https://in.mathworks.com/help/supportpkg/arduinoio/ref/readvoltage.html
  4. Follow custom library workflow for TridentTD_Linenotify, https://in.mathworks.com/help/supportpkg/arduinoio/custom-arduino-libraries.html
Please feel free to contact our Technical Support Team if you run into any issues,
https://www.mathworks.com/support/contact_us.html
Thanks,
MATLAB Hardware Team
MathWorks

Tags

Community Treasure Hunt

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

Start Hunting!