Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@1:e9cb1aec787c, 2017-11-06 (annotated)
- Committer:
- rossatmsoe
- Date:
- Mon Nov 06 01:12:21 2017 +0000
- Revision:
- 1:e9cb1aec787c
- Parent:
- 0:ab5b6bca3e25
- Child:
- 2:300f689e33b5
Updated to include MATLAB code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rossatmsoe | 0:ab5b6bca3e25 | 1 | #include "mbed.h" |
| rossatmsoe | 0:ab5b6bca3e25 | 2 | /* MATLAB can send data over to the Nucleo to control its operation or |
| rossatmsoe | 0:ab5b6bca3e25 | 3 | to output data via AnalogOut, etc. In this case, MATLAB sends a number and the |
| rossatmsoe | 0:ab5b6bca3e25 | 4 | onboard LED is set to blink that many times in 2 seconds. |
| rossatmsoe | 1:e9cb1aec787c | 5 | |
| rossatmsoe | 1:e9cb1aec787c | 6 | MATLAB can connect to Nucleo using the serial object defined in MATLAB. |
| rossatmsoe | 1:e9cb1aec787c | 7 | Here is MATLAB code to send number: |
| rossatmsoe | 1:e9cb1aec787c | 8 | |
| rossatmsoe | 1:e9cb1aec787c | 9 | >> nucleo = serial('COM3','BaudRate',9600); %(replace with your COM channel) |
| rossatmsoe | 1:e9cb1aec787c | 10 | >> fopen(nucleo); |
| rossatmsoe | 1:e9cb1aec787c | 11 | >> fprintf(nucleo,'5\n'); %This line can be repeated with values other than 5 |
| rossatmsoe | 1:e9cb1aec787c | 12 | >> fclose(nucleo); %When you are all done, close connection |
| rossatmsoe | 1:e9cb1aec787c | 13 | >> clear s; %Clear object from memory |
| rossatmsoe | 1:e9cb1aec787c | 14 | |
| rossatmsoe | 0:ab5b6bca3e25 | 15 | */ |
| rossatmsoe | 0:ab5b6bca3e25 | 16 | PwmOut light(LED1); |
| rossatmsoe | 0:ab5b6bca3e25 | 17 | Serial matlab(USBTX,USBRX); |
| rossatmsoe | 0:ab5b6bca3e25 | 18 | int main() { |
| rossatmsoe | 0:ab5b6bca3e25 | 19 | int x; |
| rossatmsoe | 0:ab5b6bca3e25 | 20 | light=0.5; // turn on light |
| rossatmsoe | 0:ab5b6bca3e25 | 21 | while(1){ |
| rossatmsoe | 0:ab5b6bca3e25 | 22 | matlab.scanf("%d",&x); // get number from MATLAB |
| rossatmsoe | 0:ab5b6bca3e25 | 23 | light.period(2.0/x); // set new period for blinking |
| rossatmsoe | 0:ab5b6bca3e25 | 24 | } |
| rossatmsoe | 0:ab5b6bca3e25 | 25 | |
| rossatmsoe | 0:ab5b6bca3e25 | 26 | } |