Please enable JavaScript.
Coggle requires JavaScript to display documents.
Keyboard Control for Robot (example of one way to acess keyboard (Line 8 -…
Keyboard Control for Robot
make sure you always have a way to cleanly exit your programs
ex: case 'q' break;
example of one way to acess keyboard
declare a global var key
Line 1: global key
Initializes the Figure 1 window that listens for key presses. Any key that is pressed is copied into the "key" variable
Line 2 – InitKeyboard();
set up a loop that runs until the break is called
Line 3 - while 1
Pause the code for 0.1 seconds.
Line 5 – pause(0.1) (enter was pressed in b/w)
start a switch case statement based on the variable "key"
Line 6 – switch key (line 7 is nothing, enter was pressed)
Line 8 - case 'uparrow'
Line 9 - disp('Up arrow pressed!');
Line 11 - case 'downarrow'
Line 12 - disp('Down arrow pressed!');
goes on - left arrow & right arrow until - case 0 disp('no arrow pressed'); and then case 'q' break;
end
at the very end of a program that initiates keyboard do this:
CloseKeyboard();
ALWAYS do this