File tree 2 files changed +27
-3
lines changed
examples/Modulino_Knob/Knob_Basic
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,21 @@ void loop(){
24
24
int position = knob.get ();
25
25
// Check if the knob has been pressed (clicked)
26
26
bool click = knob.isPressed ();
27
+ // Get the rotation direction
28
+ int8_t direction = knob.getDirection ();
27
29
28
30
Serial.print (" Current position is: " );
29
31
Serial.println (position);
30
32
31
- if (click){
33
+ if (click) {
32
34
Serial.println (" Clicked!" );
33
35
}
34
36
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 {
274
274
}
275
275
return ret;
276
276
}
277
- int16_t get () {
277
+ bool update () {
278
278
uint8_t buf[3 ];
279
279
auto res = read (buf, 3 );
280
280
if (res == false ) {
281
281
return 0 ;
282
282
}
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
+ }
283
298
_pressed = (buf[2 ] != 0 );
284
299
int16_t ret = buf[0 ] | (buf[1 ] << 8 );
285
300
return ret;
You can’t perform that action at this time.
0 commit comments