File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
examples/Modulino_Knob/Knob_Basic Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,21 @@ void loop(){
2424 int position = knob.get ();
2525 // Check if the knob has been pressed (clicked)
2626 bool click = knob.isPressed ();
27+ // Get the rotation direction
28+ int8_t direction = knob.getDirection ();
2729
2830 Serial.print (" Current position is: " );
2931 Serial.println (position);
3032
31- if (click){
33+ if (click) {
3234 Serial.println (" Clicked!" );
3335 }
3436
35- }
37+ if (direction == 1 ) {
38+ Serial.println (" Rotated clockwise" );
39+ } else if (direction == -1 ) {
40+ Serial.println (" Rotated counter-clockwise" );
41+ }
42+
43+ delay (10 ); // optional small delay to reduce serial spam
44+ }
Original file line number Diff line number Diff line change @@ -274,12 +274,27 @@ class ModulinoKnob : public Module {
274274 }
275275 return ret;
276276 }
277- int16_t get () {
277+ bool update () {
278278 uint8_t buf[3 ];
279279 auto res = read (buf, 3 );
280280 if (res == false ) {
281281 return 0 ;
282282 }
283+ get (buf);
284+ return 1 ;
285+ }
286+ int16_t get (uint8_t * buf = nullptr ) {
287+ if (buf == nullptr ) {
288+ buf = (uint8_t *)malloc (3 );
289+ if (buf == nullptr ) {
290+ return 0 ;
291+ }
292+ auto res = read (buf, 3 );
293+ if (res == false ) {
294+ _pressed = false ;
295+ return 0 ;
296+ }
297+ }
283298 _pressed = (buf[2 ] != 0 );
284299 int16_t ret = buf[0 ] | (buf[1 ] << 8 );
285300 return ret;
You can’t perform that action at this time.
0 commit comments