simple matlab script to communicate with a monome grid usingf serial port functions
| % get a list of devices connected to serial ports | |
| % create a serial port object (s) -- on my computer it was the 6th device | |
| a = seriallist; | |
| s = serial(a{6}); | |
| s.Terminator = 'CR'; | |
| % open serial port object | |
| fopen(s) | |
| % FREAD: 3 bytes for the input buffer | |
| % byte 1 = type of event of detected (33 is button press, 32 is button release) | |
| % byte 2 = column of event | |
| % byte 3 = row of event | |
| % FWRITE: 4 bytes to the grid to control LEDs | |
| % byte 1 = type of event of detected (33 is button press, 32 is button release) | |
| % byte 2 = column of button | |
| % byte 3 = row of button | |
| % byte 4 = intensity of LED (0-15) | |
| % apologies for the infinite loop - use Ctrl-Break to exit | |
| % be sure to use fclose(s) after exiting the loop | |
| while 1==1 | |
| % read input buffer | |
| A = fread(s,3); | |
| % if an event if detected | |
| if ~isempty(A) | |
| % turn on led | |
| if A(1)==33 | |
| fwrite(s,[24 A(2) A(3) 15]); | |
| % display column and row of button pressed | |
| disp([A(2) A(3)]); | |
| end | |
| % turn off led | |
| if A(1)==32 | |
| fwrite(s,[24 A(2) A(3) 0]); | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment