{"id":174,"date":"2024-04-18T21:24:54","date_gmt":"2024-04-19T04:24:54","guid":{"rendered":"https:\/\/scottwong.com\/?p=174"},"modified":"2024-04-19T11:54:27","modified_gmt":"2024-04-19T18:54:27","slug":"1d6-arduino","status":"publish","type":"post","link":"https:\/\/scottwong.com\/?p=174","title":{"rendered":"1D6 arduino"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">here&#8217;s some text<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/t3.ftcdn.net\/jpg\/03\/35\/18\/02\/360_F_335180208_DN9gHHwmEltKxSB1BfE4YjqMvzZyHkwK.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Code:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>const int LED_BIT_1 = 12;         \/\/ I designated the LEDS to each of the respective PINS:\nconst int LED_BIT_2 = 11;         \/\/ Feel free to change the PINS to whatever of your choosing!\nconst int LED_BIT_4 = 10;         \/\/ \nconst int LED_BIT_6 = 9;          \/\/ \n\nconst int PAUSE = 2000;           \/\/ 2000ms, or 2 seconds, a good representation as a length of time to show the Face of the dice.    \n\nconst int BUTTON_PIN = 7;         \/\/ Again, I designated the Button to be on PIN 7. Feel free to change to whatever is easiest for you.\n\nint currentButtonValue = 0;\nint previousButtonValue = 0;\n\nvoid setup() {\n  pinMode(LED_BIT_1, OUTPUT);         \/\/ Center PIP lights up\n  pinMode(LED_BIT_2, OUTPUT);         \/\/ UR + DL PIPS light up\n  pinMode(LED_BIT_4, OUTPUT);         \/\/ UL + DR PIPS light up\n  pinMode(LED_BIT_6, OUTPUT);         \/\/ CL + CR PIPS light up\n\n  pinMode(BUTTON_PIN, INPUT);         \/\/ This the button, used as an input.\n  \n  \/\/ Seed the random number generator with analogRead\n  randomSeed(analogRead(A0));\n}\n\nvoid loop() {\n  currentButtonValue = digitalRead(BUTTON_PIN);   \/\/ Read the Button state\n\n  switch (currentButtonValue) {\n    case LOW:\n    \/\/ Button is not pressed, turn off all the LEDS\n    digitalWrite(LED_BIT_1, LOW);\n    digitalWrite(LED_BIT_2, LOW);\n    digitalWrite(LED_BIT_4, LOW);\n    digitalWrite(LED_BIT_6, LOW);\n    break;\n\n    case HIGH:\n    \/\/ Button is pressed, control LEDs based on switch-case\n    int randomNumber = random(1, 7);   \/\/ Generate a random number between 1 and 6\n\n    switch (randomNumber) {\n      case 1:\n      \/\/ Dice rolls a \"1\": Center PIP lights up\n        digitalWrite(LED_BIT_1, HIGH);\n        digitalWrite(LED_BIT_2, LOW);\n        digitalWrite(LED_BIT_4, LOW);\n        digitalWrite(LED_BIT_6, LOW);\n        break;\n\n      case 2:\n      \/\/ Dice rolls a \"2\": Upper Right and Bottom Left PIPS light up\n        digitalWrite(LED_BIT_1, LOW);\n        digitalWrite(LED_BIT_2, HIGH);\n        digitalWrite(LED_BIT_4, LOW);\n        digitalWrite(LED_BIT_6, LOW);\n        break;\n        \n      case 3:\n      \/\/ Dice rolls a \"3\": Upper Right and Bottom Left PIPS light up, as well as the Center PIP.\n        digitalWrite(LED_BIT_1, HIGH);\n        digitalWrite(LED_BIT_2, HIGH);\n        digitalWrite(LED_BIT_4, LOW);\n        digitalWrite(LED_BIT_6, LOW);\n        break;\n\n      case 4:\n      \/\/ Dice rolls a \"4\": Upper Left and Bottom Right PIPS light up, in addition to case 2: (Upper Right and Bottom Left PIPS light up.)\n        digitalWrite(LED_BIT_1, LOW);\n        digitalWrite(LED_BIT_2, HIGH);\n        digitalWrite(LED_BIT_4, HIGH);\n        digitalWrite(LED_BIT_6, LOW);\n        break;\n\n      case 5:\n      \/\/ Dice rolls a \"5\": Upper Left and Bottom Right PIPS light up, in addition to case 2: (Upper Right and Bottom Left PIPS light up.)\n      \/\/ the Center PIP lights up, too.\n        digitalWrite(LED_BIT_1, HIGH);\n        digitalWrite(LED_BIT_2, HIGH);\n        digitalWrite(LED_BIT_4, HIGH);\n        digitalWrite(LED_BIT_6, LOW);\n        break;\n\n      case 6:\n      \/\/ Dice rolls a \"6\": Upper Left and Bottom Right PIPS light up, in addition to case 2: (Upper Right and Bottom Left PIPS light up.)\n      \/\/ the Center Left\/Right PIPS light up, too.\n        digitalWrite(LED_BIT_1, LOW);\n        digitalWrite(LED_BIT_2, HIGH);\n        digitalWrite(LED_BIT_4, HIGH);\n        digitalWrite(LED_BIT_6, HIGH);\n        break;\n    }\n\n    delay(PAUSE);     \/\/ Delay for PAUSE value listed above (default: 2000 ms, or 2 seconds)\n  }\n}\n\n\n\/*  Visual LOGIC for 1D6 rolls: 1, 2, 3, 4, 5, 6 \n\/\/  The code below was used for TESTING\/logic purposes, only, to make sure a cycled 1-6 would work!\n\nvoid loop() {\n  \/\/ LED pattern for case 1\n  digitalWrite(LED_BIT_1, HIGH);\n  digitalWrite(LED_BIT_2, LOW);\n  digitalWrite(LED_BIT_4, LOW);\n  digitalWrite(LED_BIT_6, LOW);\n  delay(PAUSE);\n\n  \/\/ LED pattern for case 2\n  digitalWrite(LED_BIT_1, LOW);\n  digitalWrite(LED_BIT_2, HIGH);\n  digitalWrite(LED_BIT_4, LOW);\n  digitalWrite(LED_BIT_6, LOW);\n  delay(PAUSE);\n  \n  \/\/ LED pattern for case 3\n  digitalWrite(LED_BIT_1, HIGH);\n  digitalWrite(LED_BIT_2, HIGH);\n  digitalWrite(LED_BIT_4, LOW);\n  digitalWrite(LED_BIT_6, LOW);\n  delay(PAUSE);\n  \n  \/\/ LED pattern for case 4\n  digitalWrite(LED_BIT_1, LOW);\n  digitalWrite(LED_BIT_2, HIGH);\n  digitalWrite(LED_BIT_4, HIGH);\n  digitalWrite(LED_BIT_6, LOW);\n  delay(PAUSE);\n  \n  \/\/ LED pattern for case 5\n  digitalWrite(LED_BIT_1, HIGH);\n  digitalWrite(LED_BIT_2, HIGH);\n  digitalWrite(LED_BIT_4, HIGH);\n  digitalWrite(LED_BIT_6, LOW);\n  delay(PAUSE);\n  \n  \/\/ LED pattern for case 6\n  digitalWrite(LED_BIT_1, LOW);\n  digitalWrite(LED_BIT_2, HIGH);\n  digitalWrite(LED_BIT_4, HIGH);\n  digitalWrite(LED_BIT_6, HIGH);\n  delay(PAUSE);\n  \n}\n\n*\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>here&#8217;s some text Code:<\/p>\n","protected":false},"author":1,"featured_media":177,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[14,18,15],"tags":[20,31,30],"class_list":["post-174","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-programming","category-project","tag-arduino","tag-github","tag-programming","entry","has-media"],"_links":{"self":[{"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scottwong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=174"}],"version-history":[{"count":3,"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions\/271"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/scottwong.com\/index.php?rest_route=\/wp\/v2\/media\/177"}],"wp:attachment":[{"href":"https:\/\/scottwong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scottwong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scottwong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}