{"id":159,"date":"2014-08-06T23:35:36","date_gmt":"2014-08-06T23:35:36","guid":{"rendered":"https:\/\/www.cyberia.at\/?page_id=159"},"modified":"2022-09-15T23:33:18","modified_gmt":"2022-09-15T23:33:18","slug":"7-segment-dice","status":"publish","type":"page","link":"https:\/\/www.cyberia.at\/?page_id=159","title":{"rendered":"7-Segment Dice"},"content":{"rendered":"<p>\/\/(Diagram to follow)<\/p>\n<div style=\"width: 480px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-159-1\" width=\"480\" height=\"480\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.cyberia.at\/wp-content\/uploads\/2014\/08\/Arduino-dice.mp4?_=1\" \/><a href=\"https:\/\/www.cyberia.at\/wp-content\/uploads\/2014\/08\/Arduino-dice.mp4\">https:\/\/www.cyberia.at\/wp-content\/uploads\/2014\/08\/Arduino-dice.mp4<\/a><\/video><\/div>\n<p>\/*<\/p>\n<p>Basic 7-seg LED dice<\/p>\n<p>Generates a random integer between 0 and 6,<br \/>\nthen outputs it to an HDSP-C3G3 7 segment display every 5 seconds.<\/p>\n<p>Kate A. Glover &#8211; kateglover@gmail.com<br \/>\n*\/<\/p>\n<p>\/* This matches up each lettered pin-out on the 7-seg display<br \/>\nwith a given port number on the Arduino Uno*\/<\/p>\n<p style=\"padding-left: 30px;\">int a = 2;<br \/>\nint b = 3;<br \/>\nint c = 4;<br \/>\nint d = 5;<br \/>\nint e = 6;<br \/>\nint f = 7;<br \/>\nint g = 8;<\/p>\n<p>void setup() {<br \/>\n\/\/ initialize each digital pin as an output.<\/p>\n<p style=\"padding-left: 30px;\">pinMode(a, OUTPUT);<br \/>\npinMode(b, OUTPUT);<br \/>\npinMode(c, OUTPUT);<br \/>\npinMode(d, OUTPUT);<br \/>\npinMode(e, OUTPUT);<br \/>\npinMode(f, OUTPUT);<br \/>\npinMode(g, OUTPUT);<\/p>\n<p>}<\/p>\n<p>\/\/ loops to produce a number every 5 seconds (5000 milliseconds)<br \/>\nvoid loop()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">\/\/creates an int from a number returned by the generateNumber() method.<br \/>\nint randNo = generateNumber();<\/p>\n<p>\/\/calls a different method depending on which number was generated<br \/>\nswitch (randNo)<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">case 1:<\/p>\n<p style=\"padding-left: 60px;\">displayOne();<br \/>\nbreak;<\/p>\n<p style=\"padding-left: 30px;\">case 2:<\/p>\n<p style=\"padding-left: 60px;\">displayTwo();<br \/>\nbreak;<\/p>\n<p style=\"padding-left: 30px;\">case 3:<\/p>\n<p style=\"padding-left: 60px;\">displayThree();<br \/>\nbreak;<\/p>\n<p style=\"padding-left: 30px;\">case 4:<\/p>\n<p style=\"padding-left: 60px;\">displayFour();<br \/>\nbreak;<\/p>\n<p style=\"padding-left: 30px;\">case 5:<\/p>\n<p style=\"padding-left: 60px;\">displayFive();<br \/>\nbreak;<\/p>\n<p style=\"padding-left: 30px;\">case 6:<\/p>\n<p style=\"padding-left: 60px;\">displaySix();<br \/>\nbreak;<\/p>\n<p style=\"padding-left: 30px;\">\/* this default calls a method which displays an &#8220;E&#8221; (for error)<br \/>\nand only shows when a number is called which is out of range. *\/<\/p>\n<p style=\"padding-left: 30px;\">default:<\/p>\n<p style=\"padding-left: 60px;\">displayFault();<br \/>\nbreak;<\/p>\n<p>}<br \/>\n\/\/5000 millisecond (5 second) delay before it calls another number<\/p>\n<p style=\"padding-left: 30px;\">delay(5000);<\/p>\n<p>}<\/p>\n<p>\/\/generates the random number and returns it to the main loop() method.<br \/>\nint generateNumber()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">randomSeed(analogRead(0));<br \/>\nint randomNumber = random(1, 6);<br \/>\nreturn randomNumber;<\/p>\n<p>}<\/p>\n<p>\/\/ Fires up pins to create a number 1 and shuts off the other pins<br \/>\nvoid displayOne()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, LOW);<br \/>\ndigitalWrite(b, HIGH);<br \/>\ndigitalWrite(c, HIGH);<br \/>\ndigitalWrite(d, LOW);<br \/>\ndigitalWrite(e, LOW);<br \/>\ndigitalWrite(f, LOW);<br \/>\ndigitalWrite(g, LOW);<\/p>\n<p>}<\/p>\n<p>\/\/ Fires up pins to create a number 2 and shuts off the other pins<br \/>\nvoid displayTwo()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, HIGH);<br \/>\ndigitalWrite(b, HIGH);<br \/>\ndigitalWrite(c, LOW);<br \/>\ndigitalWrite(d, HIGH);<br \/>\ndigitalWrite(e, HIGH);<br \/>\ndigitalWrite(f, LOW);<br \/>\ndigitalWrite(g, HIGH);<\/p>\n<p>}<\/p>\n<p>\/\/ Fires up pins to create a number 3 and shuts off the other pins<br \/>\nvoid displayThree()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, HIGH);<br \/>\ndigitalWrite(b, HIGH);<br \/>\ndigitalWrite(c, HIGH);<br \/>\ndigitalWrite(d, HIGH);<br \/>\ndigitalWrite(e, LOW);<br \/>\ndigitalWrite(f, LOW);<br \/>\ndigitalWrite(g, HIGH);<\/p>\n<p>}<\/p>\n<p>\/\/ and so on and so forth<br \/>\nvoid displayFour()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, LOW);<br \/>\ndigitalWrite(b, HIGH);<br \/>\ndigitalWrite(c, HIGH);<br \/>\ndigitalWrite(d, LOW);<br \/>\ndigitalWrite(e, LOW);<br \/>\ndigitalWrite(f, HIGH);<br \/>\ndigitalWrite(g, HIGH);<\/p>\n<p>}<\/p>\n<p>\/\/ You get the idea<br \/>\nvoid displayFive()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, HIGH);<br \/>\ndigitalWrite(b, LOW);<br \/>\ndigitalWrite(c, HIGH);<br \/>\ndigitalWrite(d, HIGH);<br \/>\ndigitalWrite(e, LOW);<br \/>\ndigitalWrite(f, HIGH);<br \/>\ndigitalWrite(g, HIGH);<\/p>\n<p>}<\/p>\n<p>\/\/ &#8230; and six&#8230;<br \/>\nvoid displaySix()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, HIGH);<br \/>\ndigitalWrite(b, LOW);<br \/>\ndigitalWrite(c, HIGH);<br \/>\ndigitalWrite(d, HIGH);<br \/>\ndigitalWrite(e, HIGH);<br \/>\ndigitalWrite(f, HIGH);<br \/>\ndigitalWrite(g, HIGH);<\/p>\n<p>}<\/p>\n<p>\/\/ Sets the display to show an E (for error)<br \/>\nvoid displayFault()<br \/>\n{<\/p>\n<p style=\"padding-left: 30px;\">digitalWrite(a, HIGH);<br \/>\ndigitalWrite(b, LOW);<br \/>\ndigitalWrite(c, LOW);<br \/>\ndigitalWrite(d, HIGH);<br \/>\ndigitalWrite(e, HIGH);<br \/>\ndigitalWrite(f, HIGH);<br \/>\ndigitalWrite(g, HIGH);<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/(Diagram to follow) \/* Basic 7-seg LED dice Generates a random integer between 0 and 6, then outputs it to an HDSP-C3G3 7 segment display every 5 seconds. Kate A. Glover &#8211; kateglover@gmail.com *\/ \/* This matches up each lettered pin-out on the 7-seg display with a given port number on the Arduino Uno*\/ int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":156,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"page-full-width.php","meta":{"footnotes":""},"class_list":["post-159","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/pages\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberia.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=159"}],"version-history":[{"count":3,"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/pages\/159\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/pages\/159\/revisions\/165"}],"up":[{"embeddable":true,"href":"https:\/\/www.cyberia.at\/index.php?rest_route=\/wp\/v2\/pages\/156"}],"wp:attachment":[{"href":"https:\/\/www.cyberia.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}