User Tools

Site Tools


mmbasic:reprap_20x4_lcd_encoder_wheel_support

RepRap 20x4 LCD Encoder Wheel support

encoder_spin.txt

The Basic code to support the RepRap 20×4 LCD Encoder Wheels is provided here: http://fruitoftheshed.com/GetFile.aspx?File=%2fMMBasic%2fEncoder_Spin.txt&AsStreamAttachment=1&Provider=ScrewTurn.Wiki.FilesStorageProvider&NoHit=1

Or… You can just cut and paste from this post:

Sub Setup_LCD

 SetPin GP7, DOUT       'Beeper
 Pin(GP7) = 1           'Beeper On
 Bitbang LCD INIT GP11,GP12,GP14,GP15,  GP22,GP26
 Bitbang LCD Clear
 Pin(GP7) = 0           'Beeper Off

End Sub

Sub Setup_Encoder_Pins

 SetPin GP24, DIN, PULLUP             'Pico User Switch
 SetPin GP10, DIN, PULLUP             'Encoder Button Pressed
 SetPin GP28, INTB, Enc_Spin, PULLUP  'Encoder Phase-1
 SetPin GP29, INTB, Enc_Spin, PULLUP  'Encoder Phase-2
 SetPin GP27, DIN, PULLUP             'Kill Button

End Sub

Sub Enc_Spin

  Static integer e1%, e2%, last_e1%, last_e2%
  e1% = Pin(GP28)
  e2% = Pin(GP29)
  If e1% <> last_e1% And e2% <> last_e2% Then GoTo Leave_Enc_Spin
  On (last_e1% << 1) + last_e2% + 1  GoTo 240,230,250,260
  GoTo Leave_Enc_Spin

230 On (e1% « 1) + e2% + 1 GoTo 233, Leave_Enc_Spin, Leave_Enc_Spin, 236 233 enc_val% = enc_val% + 1 : ' Clockwise

  GoTo Leave_Enc_Spin

236 enc_val% = enc_val% - 1 : ' counter Clockwise

  GoTo Leave_Enc_Spin

240 On (e1% « 1) + e2% + 1 GoTo Leave_Enc_Spin, 244, 245, Leave_Enc_Spin 244 enc_val% = enc_val% - 1 : ' counter Clockwise

  GoTo Leave_Enc_Spin

245 enc_val% = enc_val% + 1 : ' Clockwise

  GoTo Leave_Enc_Spin

250 On (e1% « 1) + e2% + 1 GoTo 251, Leave_Enc_Spin, Leave_Enc_Spin, 254 251 enc_val% = enc_val% - 1 : ' counter Clockwise

  GoTo Leave_Enc_Spin

254 enc_val% = enc_val% + 1 : ' Clockwise

  GoTo Leave_Enc_Spin

260 On (e1% « 1) + e2% + 1 GoTo Leave_Enc_Spin, 262, 263, Leave_Enc_Spin 262 enc_val% = enc_val% + 1 : ' Clockwise

  GoTo Leave_Enc_Spin

263 enc_val% = enc_val% - 1 : ' counter Clockwise

  GoTo Leave_Enc_Spin

Leave_Enc_Spin:

  last_e1% = e1%
  last_e2% = e2%
  End Sub
  End
mmbasic/reprap_20x4_lcd_encoder_wheel_support.txt · Last modified: 2024/01/19 09:30 by 127.0.0.1