WOKWI Project : free / occupied Display with MAX7219

Place your projects here
Post Reply
User avatar
PeterN
Posts: 403
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 193 times
Been thanked: 225 times
Contact:

WOKWI Project : free / occupied Display with MAX7219

Post by PeterN »

:? As an example project for a German programming beginner, I "built" a display for the free/occupied display of a restaurant toilet with WOKWI, which is well documented for once.
Unfortunately only in German ( - but I see that many Annex users come from there ;-) EDIT: NOW IN ENGLISH TOO
Certainly not a masterpiece of programming - but perhaps a good example for beginners, whereby my intention was to lead the beginner to a place where more good Annex32 examples are collected

Perhaps this can encourage other Annex colleagues and friends to post their project treasures here in a similar form ?
BANNER_WC.jpg

--> THE WOKWI-EXAMPLE GERMAN version: https://wokwi.com/projects/381019726127067137
--> THE WOKWI-EXAMPLE ENGLISH version: https://wokwi.com/projects/381736361676924929

Don't forget to press the ">" play-button there to start the simulation.


EDIT: To spread the good news more ... https://www.elektormagazine.de/labs/wok ... th-max7219


Code: [Local Link Removed for Guests]

'WC*FREE*/OCCUPY display with X*8x8 modules MAX7219 matrix
'
' After starting, briefly shows your own IP address and
' the text "right", "left" and "center".
' Then it will display endlessly in the middle...
' - the current time for 3 seconds
' - for 2 seconds the text "WC *FREI*" or "WC OCCUPY"
'   depending on the status of an external switch between pin 33 and GND.
' The pin is pulled up to 3V3 with PULLUP.
' If the cable to the switch is longer, pin 33 should should be pulled up more
' as a precautionary measure with a 1k resistor to 3V3.



WLOG "START"      ' Definition of some variables that should have certain values at start-up
VERSION$        = "2.0" 'TextVariable with the current program version
'DISPLAY_NUMBER = 10 'Number of 8*8 modules
DISPLAY_NUMBER  = 8 'Number of 8*8 modules
DISPLAY_PIN     = 15 'CS pin of the display
DISPLAY_PIXEL   = DISPLAY_NUMBER*8 'Number of horizontal pixels in the display
CHAR_PIXEL      = 6 'Number of pixels for a single character
POSITION        = 0 'Variable for the text position (starting from the right!)
SECONDS_COUNTER = 0 'Variable for loop counter
SWITCH_PIN      = 33 'Variable with the pin on which a switch to GND is attached
DOOR_STATUS     = 1 ' 1 = switch open, O = switch closed
OPEN            = 1 'Variable for status comparison when the switch is open
CLOSED          = 0 'Variable for status comparison when the switch is closed

TEXT_BUSY$      = "WC BUSY" 'Preset for busy text
TEXT_FREE$      = "WC *FREE*" 'Preset for free text


PIN.MODE SWITCH_PIN, INPUT, PULLUP 'Define a pin as an input for the switch
                              ' Pulls the PIN as an INPUT pin with a resistor to 3V3 level
                              ' The closed switch then pulls the pin to 0 volt level

'PIN.MODE SWITCH_PIN, INPUT, PULLDOWN 'If this line is not commented out,
                                      ' this simulates a closed switch with resistance on GND
                                      ' switches on the BUSY text as a test
WLOG "INIT Display ..."
MaxScroll.Setup DISPLAY_NUMBER,DISPLAY_PIN 'Initialize the display


' Briefly display the IP address when starting
'---------------------------------------- -------------
Text$      = Word$(IP$,1) 'The own IP address is the first word in the string IP$
TEXT_PIXEL = Len(TEXT$)*CHAR_PIXEL 'Number of horizontal pixels of this text
POSITION   = TEXT_PIXEL 'so that the right part of the address is always visible
GOSUB SHOW_THE_TEXT
PAUSE 1500


' Output text to the right
'------------------------------------------------- ----------------------------
TEXT$       = "right"
TEXT_PIXEL  = Len(TEXT$)*CHAR_PIXEL 'Number of horizontal pixels of this text
POSITION    = TEXT_PIXEL 'Position shifted to the left by text length
GOSUB SHOW_THE_TEXT
PAUSE 1000

' Output text on the left
'------------------------------------------------- -----------------------------
TEXT$       = "left"
TEXT_PIXEL  = Len(TEXT$)*CHAR_PIXEL 'Number of horizontal pixels for this text
POSITION    = DISPLAY_PIXEL 'Position is equal to number of display pixels
GOSUB SHOW_THE_TEXT
PAUSE 1000

' Output text centered
'------------------------------------------------ ----------------------------
TEXT$       = "center"
TEXT_PIXEL  = Len(TEXT$)*CHAR_PIXEL 'Number of horizontal pixels for this text
POSITION    = (DISPLAY_PIXEL/2)+(TEXT_PIXEL/2) 'Calculate the central output position
GOSUB SHOW_THE_TEXT
PAUSE 1000

' Now the Timer0 takes over the regular control once per second
'------------------------------------------------ ----------------------------
BREAK_TIME = 1000
TIMER0 BREAK_TIME, MAIN_ROUTINE 'The Timer0 now calls the subprgm endlessly every 1000ms

WAIT 'From now on only background processes will be processed;
' here is the timer0 and the ONHTMLRELOAD
END
' ################################################# ######################################
' ################################################# ######################################
' From here on there are only subprograms behind WAIT and END,
' which are called by their name from the script code above,
' and which must end with RETURN.


' - - - - - - - S U B P R O G R A M S   - - - - - - - - - - - -


'================================================= =========================
MAIN_ROUTINE:
'================================================= =========================
'This subprgm is called once per second by TIMER0.
'The current time should be called up for the first three calls.
'The free or busy text should then be displayed for two seconds.
'To do this, the input pin is queried with the external switch.
SECONDS_COUNTER = SECONDS_COUNTER + 1' increase counter
SELECT CASE SECONDS_COUNTER
  CASE 1, 2, 3      'Second 1 to 3:
    TEXT$ = TIME$   'TEXT$ now contains the current time
  CASE 4 , 5        'Second 4 and 5
    DOOR_STATUS    = PIN(SWITCH_PIN) 'DOOR_STATUS is now 0 or 1, depending on switch status
    IF DOOR_STATUS = OPEN then TEXT$ = TEXT_FREE$ 'FREE!!
    IF DOOR_STATUS = CLOSED then TEXT$ = TEXT_OCCUPY$ 'OCCUPY!!
END SELECT

SECONDS_COUNTER = SECONDS_COUNTER mod 5  'Set SECONDS_COUNTER AT 5 back to 0
GOSUB SHOW_THE_TEXT_CENTERED             'Show Text$
RETURN

'================================================= =========================
SHOW_THE_TEXT:
'================================================= =========================
MAXSCROLL.PRINT TEXT$   'here TEXT$ only goes into the buffer
MAXSCROLL.SHOW POSITION 'Only now will the buffer be displayed at the position
WLOG TEXT$              'In addition only for feedback in the development interface
RETURN                  'Back to the calling line

'================================================= =========================
SHOW_THE_TEXT_CENTERED:
'================================================= =========================
TEXT_PIXEL = Len(TEXT$)*CHAR_PIXEL            'Number of horizontal pixels for this text
POSITION   = (DISPLAY_PIXEL/2)+(TEXT_PIXEL/2) 'Calculate the central output position
GOSUB SHOW_THE_TEXT
RETURN

You do not have the required permissions to view the files attached to this post.
Post Reply