{"id":288,"date":"2024-03-11T05:59:15","date_gmt":"2024-03-11T05:59:15","guid":{"rendered":"https:\/\/blog.kevinsiraki.com\/?p=288"},"modified":"2024-03-11T06:07:14","modified_gmt":"2024-03-11T06:07:14","slug":"5x7-matrix-code","status":"publish","type":"post","link":"https:\/\/blog.kevinsiraki.com\/?p=288","title":{"rendered":"5&#215;7 Matrix Code"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This is the Arduino code for my 5&#215;7 Matrix LED display video demonstration:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Scrolling \u201cHello World\u201d on 5x7 LED Matrix with Arduino Uno\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/XpkrDH9yLgY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">Original YouTube Shorts Video<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\n#include \"FrequencyTimer2.h\"\n \n#define SPACE { \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0} \\\n}\n \n#define H { \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 1, 1, 1, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1} \\\n}\n \n#define E { \\\n{1, 1, 1, 1, 1}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 1, 1, 1, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 1, 1, 1, 1} \\\n}\n \n#define small_E { \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 1, 1, 1, 0}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 1, 1, 1, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{0, 1, 1, 1, 0} \\\n}\n \n#define L { \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 0}, \\\n{1, 1, 1, 1, 1} \\\n}\n \n#define small_L { \\\n{0, 1, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 1, 1, 1, 0} \\\n}\n \n#define O { \\\n{0, 1, 1, 1, 0}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{0, 1, 1, 1, 0} \\\n}\n \n#define small_O { \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 1, 1, 1, 0}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{0, 1, 1, 1, 0} \\\n}\n \n#define small_W { \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 1, 0, 1}, \\\n{1, 0, 1, 0, 1}, \\\n{0, 1, 0, 1, 0} \\\n}\n \n#define small_R { \\\n{0, 0, 0, 0, 0}, \\\n{0, 0, 0, 0, 0}, \\\n{0, 1, 0, 1, 1}, \\\n{0, 1, 1, 0, 0}, \\\n{0, 1, 0, 0, 0}, \\\n{0, 1, 0, 0, 0}, \\\n{0, 1, 0, 0, 0} \\\n}\n \n#define small_D { \\\n{0, 0, 0, 0, 1}, \\\n{0, 0, 0, 0, 1}, \\\n{0, 1, 1, 0, 1}, \\\n{1, 0, 0, 1, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{0, 1, 1, 1, 1} \\\n}\n\n#define big_K { \\\n {1,0,0,0,1},\\\n {1,0,0,1,0},\\\n {1,0,1,0,0},\\\n {1,1,0,0,0},\\\n {1,0,1,0,0},\\\n {1,0,0,1,0},\\\n {1,0,0,0,1},\\\n}\n\n#define big_V { \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{1, 0, 0, 0, 1}, \\\n{0, 1, 0, 1, 0}, \\\n{0, 0, 1, 0, 0} \\\n}\n\n#define big_I { \\\n{1, 1, 1, 1, 1}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{0, 0, 1, 0, 0}, \\\n{1, 1, 1, 1, 1} \\\n}\n\n#define big_N { \\\n{1,0,0,0,1},\\\n{1,0,0,0,1},\\\n{1,1,0,0,1},\\\n{1,0,1,0,1},\\\n{1,0,0,1,1},\\\n{1,0,0,0,1},\\\n{1,0,0,0,1},\\\n}\n\n\n\n\n\nbyte col = 0;\nbyte leds&#91;5]&#91;7]; \/\/ columns x rows\n \n\/\/ pin&#91;xx] on led matrix connected to nn on Arduino\n\/\/ (-1 is dummy to make array start at pos 1)\nint pins&#91;13]= {-1, 2,3,4,5,6,7,8,9,10,11,12,13};\n \n\/\/ col&#91;xx] of leds = pin yy on led matrix\nint cols&#91;5] = {pins&#91;8], pins&#91;9], pins&#91;10], pins&#91;11], pins&#91;12]};\n \n\/\/ row&#91;xx] of leds = pin yy on led matrix\nint rows&#91;7] = {pins&#91;1], pins&#91;2], pins&#91;3], pins&#91;4],\n pins&#91;5], pins&#91;6], pins&#91;7]};\n \nconst int numPatterns = 11;\nbyte patterns&#91;numPatterns]&#91;7]&#91;5] = {\n SPACE, big_K,SPACE,E,SPACE,big_V,SPACE,big_I,SPACE,big_N, SPACE \n };\n\n \nint pattern = 0;\n \nvoid setup()\n{\n  \/\/ sets the pins as output\n  for (int i = 1; i &lt;= 12; i++) {\n    pinMode(pins&#91;i], OUTPUT);\n  }\n \n  \/\/ set up cols and rows\n  for (int i = 1; i &lt;= 5; i++) {\n    digitalWrite(cols&#91;i - 1], LOW);\n  }\n \n  for (int i = 1; i &lt;= 7; i++) {\n    digitalWrite(rows&#91;i - 1], LOW);\n  }\n \n  clearLeds();\n \n  \/\/ Turn off toggling of pin 11\n  FrequencyTimer2::disable();\n  \/\/ Set refresh rate (interrupt timeout period)\n  FrequencyTimer2::setPeriod(2000);\n  \/\/ Set interrupt routine to be called\n  FrequencyTimer2::setOnOverflow(display);\n \n  setPattern(pattern);\n}\n \nvoid loop()\n{\n  pattern = ++pattern % numPatterns;\n  slidePattern(pattern, 100);\n}\n \nvoid clearLeds()\n{\n  \/\/ Clear display array\n  for (int i = 0; i &lt; 5; i++) {\n    for (int j = 0; j &lt; 7; j++) {\n      leds&#91;i]&#91;j] = 0;\n    }\n  }\n}\n \nvoid setPattern(int pattern)\n{\n  for (int i = 0; i &lt; 5; i++) {\n    for (int j = 0; j &lt; 7; j++) {\n      leds&#91;i]&#91;j] = patterns&#91;pattern]&#91;j]&#91;i];\n    }\n  }\n}\n \nvoid slidePattern(int pattern, int del)\n{\n  for (int newcol = 0; newcol &lt;= 4; newcol++) {\n \n    \/\/ shift the first 4 columns left\n    for (int row = 0; row &lt;= 6; row++)\n      for (int col = 0; col &lt;= 3; col++)\n        leds&#91;col]&#91;row] = leds&#91;col+1]&#91;row];\n \n    \/\/ fill the last (5th) column with the\n    \/\/ 1st (2nd, 3rd, ...) column of the new pattern\n    for (int row = 0; row &lt;= 6; row++)\n      leds&#91;4]&#91;row] = patterns&#91;pattern]&#91;row]&#91;newcol];\n \n    delay(del);\n  }\n}\n \n\/\/ Interrupt routine\nvoid display()\n{\n  \/\/ Turn whole previous column off:\n  digitalWrite(cols&#91;col], LOW);\n  col++;\n  if (col == 5) {\n    col = 0;\n  }\n  for (int row = 0; row &lt; 7; row++) {\n    if (leds&#91;col]&#91;row] == 1) {\n      digitalWrite(rows&#91;row], LOW); \/\/ Turn on this led\n    }\n    else {\n      digitalWrite(rows&#91;row], HIGH); \/\/ Turn off this led\n    }\n  }\n  \/\/ Turn whole column on at once (for equal lighting times):\n  digitalWrite(cols&#91;col], HIGH);\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is the Arduino code for my 5&#215;7 Matrix LED display video demonstration:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_EventAllDay":false,"_EventTimezone":"","_EventStartDate":"","_EventEndDate":"","_EventStartDateUTC":"","_EventEndDateUTC":"","_EventShowMap":false,"_EventShowMapLink":false,"_EventURL":"","_EventCost":"","_EventCostDescription":"","_EventCurrencySymbol":"","_EventCurrencyCode":"","_EventCurrencyPosition":"","_EventDateTimeSeparator":"","_EventTimeRangeSeparator":"","_EventOrganizerID":[],"_EventVenueID":[],"_OrganizerEmail":"","_OrganizerPhone":"","_OrganizerWebsite":"","_VenueAddress":"","_VenueCity":"","_VenueCountry":"","_VenueProvince":"","_VenueState":"","_VenueZip":"","_VenuePhone":"","_VenueURL":"","_VenueStateProvince":"","_VenueLat":"","_VenueLng":"","_VenueShowMap":false,"_VenueShowMapLink":false,"footnotes":""},"categories":[30],"tags":[27],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-electronics","tag-arduinos"],"_links":{"self":[{"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288"}],"version-history":[{"count":5,"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions\/293"}],"wp:attachment":[{"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kevinsiraki.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}