![]() |
Forum Index : Microcontroller and PC projects : MM spinning knob
Author | Message | ||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6273 |
This is a rough mockup of a control knob - volume control etc. Runs on MM Basic V4.7b23 for MX170 or MX470. Tested on 7" and 2.4" displays. ' TassyJim
' spinning knob test ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' OPTION EXPLICIT DIM knob_x = 120, knob_y = 120, knob_radius = 80, finger_radius = 20 DIM INTEGER knob_fill = RGB(178, 211, 213), knob_edge = RGB(024, 087, 197) DIM n, r, angle, tx,ty CLS FOR n = 0 TO 360 STEP 15 r=knob_draw(knob_x,knob_y,RAD(n)) PAUSE 100 NEXT n DO tx=(TOUCH(X)- knob_x) ty=(TOUCH(Y)- knob_y) IF ABS(tx) < (knob_radius+30) AND ABS(ty) < (knob_radius+30) THEN SELECT CASE tx CASE 0 IF ty<0 THEN angle = PI ELSE angle = 0 ENDIF CASE < 0 angle = ATN(ty/tx)+PI/2 CASE ELSE angle = ATN(ty/tx)+PI*1.5 END SELECT PRINT tx," ",ty," ", DEG(angle) 'DEBUG r=knob_draw(knob_x,knob_y,angle) ELSE PAUSE 100 ENDIF PAUSE 100 LOOP END FUNCTION knob_draw(x,y,a) LOCAL fingerX, fingerY CIRCLE x, y, knob_radius,6 , , knob_edge, knob_fill ' clear knob fingerX=x-SIN(a)*(knob_radius-finger_radius) fingerY=y+COS(a)*(knob_radius-finger_radius) CIRCLE fingerX, fingerY, finger_radius, 6, , knob_edge, knob_fill ' draw marker END FUNCTION The knob follows your finger/stylus around. Not as nice as PeterM's gauges but a start... Next on the list is a "slider" control. On the MM+, it would be nice to have a new GUI object - CANVAS or ZONE etc. It needs to respond to touch and is used for user designed gadgets. Having to poll the touch(X) doesn't fit well with all the other GUI objects. Jim VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |