{"id":7153,"date":"2022-02-07T07:58:31","date_gmt":"2022-02-07T07:58:31","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=7153"},"modified":"2023-08-08T16:05:56","modified_gmt":"2023-08-08T10:35:56","slug":"exercise-003-implementing-event-producer-code","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/","title":{"rendered":"FSM Lecture 27: Exercise-003 Implementing event producer code"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px;\"><strong><span style=\"color: #000080;\">Exercise-003 Implementing event producer code<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In this article, first, we will provide a couple of macros for the pins; we haven&#8217;t given that. <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let&#8217;s do that at the top in main.h as shown below.<\/span> <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">#define PIN_BUTTON1<span style=\"font-weight: 400;\">, which is <\/span>2<span style=\"font-weight: 400;\">. <\/span>#define PIN_BUTTON2<span style=\"font-weight: 400;\">, which is <\/span>3<span style=\"font-weight: 400;\">, like that. <\/span>PIN_BUTTON3<span style=\"font-weight: 400;\">&nbsp; to <\/span>Arduino PIN 4<span style=\"font-weight: 400;\">, <\/span>PIN_BUZZER<span style=\"font-weight: 400;\"> is <\/span>12<span style=\"font-weight: 400;\">.&nbsp; <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And for LCD connections, <\/span>#define PIN_LCD RS<span style=\"font-weight: 400;\">. First, let&#8217;s give the macro for RS (RS stands for register select). Then<\/span> #define PIN_LCD_RW<span style=\"font-weight: 400;\"> is <\/span>6<span style=\"font-weight: 400;\">, like that, you can do.<\/span><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #ff99cc;\">#ifndef<\/span> MAIN_H\r\n<span style=\"color: #ff99cc;\">#define<\/span> MAIN_H\r\n\r\n<span style=\"color: #ff99cc;\">#include<\/span>&lt;Arduino.h&gt;\r\n\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_BUTTON1 2\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_BUTTON2 3\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_BUTTON3 4\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_BUZZER 12\r\n\r\n<span style=\"color: #008000;\">\/\/lcd connections<\/span>\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_RS 5\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_RW 6\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_EN 7\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_D4 8\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_D5 9\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_D6 10\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_LCD_D7 11\r\n\r\n<span style=\"color: #ff99cc;\">#define<\/span> BTN_PAD_VALUE_INC_TIME 4\r\n<span style=\"color: #ff99cc;\">#define<\/span> BTN_PAD_VALUE_DEC_TIME 2\r\n<span style=\"color: #ff99cc;\">#define<\/span> BTN_PAD_VALUE_ABRT 6\r\n<span style=\"color: #ff99cc;\">#define<\/span> BTN_PAD_VALUE_SP 1<\/pre>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\">Define macros for the pins<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_7158\" aria-describedby=\"caption-attachment-7158\" style=\"width: 671px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\" wp-image-7158\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Truth-table.png\" alt=\"Figure 2. Truth table\" width=\"671\" height=\"289\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png 1803w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-300x129.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-768x331.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-1024x441.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-600x259.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-120x52.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-500x215.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-200x86.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-400x172.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-800x345.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table-1200x517.png 1200w\" sizes=\"(max-width: 671px) 100vw, 671px\" \/><figcaption id=\"caption-attachment-7158\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Truth table<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And the truth table of the button pad is shown in Figure 1. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">When the button is pressed, the button is connected to the Vcc. That means when the button is pressed, the pin status will be high. When the button is not pressed, the pin is grounded.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Suppose B3 is high, which means that the START_PAUSE button is pressed. That means, if the button pad status is 1, then that is START_PAUSE. If the button pad status is 2, then that is Decrement time. If the button pad status is 4 (binary 4), then it is Increment time. If it is 6, then it is Abort. So, other values are don\u2019t care.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Let\u2019s define those values in main.h. <\/span>#define BTN_PAD_VALUE_INC_TIME<span style=\"font-weight: 400;\"> is <\/span>4<span style=\"font-weight: 400;\">, then <\/span>#define BTN_PAD_VALUE_DEC_TIME<span style=\"font-weight: 400;\"> is <\/span>2<span style=\"font-weight: 400;\">, like that as shown in above.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Now let\u2019s implement the loop function. Let\u2019s implement the first task: read the button pad status. For this, we create a couple of variables,<\/span> uint8_t b1, b2, b3<span style=\"font-weight: 400;\">, and <\/span>btn_pad_value<span style=\"font-weight: 400;\">. b1, b2, b3 variables hold the individual button status.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">How to read the button status?&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">b1=digitalRead(). Because the button is connected to the digital pin of the Arduino, there is no Analog thing involved here. So, it\u2019s just a digitalRead.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">b1= digitalRead(PIN_BUTTON1)<span style=\"font-weight: 400;\">. Let\u2019s read the status of Button1 in b1. After that,<\/span> b2 = digitalRead(PIN_BUTTON2)<span style=\"font-weight: 400;\">, read the Button2 status to b2, likewise for Button3.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Now, <\/span>btn_pad_value= (b1&lt;&lt;2)|(b2&lt;&lt;1)|b3;<span style=\"font-weight: 400;\"> So, you have to merge all these status to form a value. You use Bitwise OR for that.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">After that, we got the button pad value. But that needs to be processed against the button bouncing.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">For the time being, let\u2019s give one function for that, which I would call <\/span>process_button_pad_value<span style=\"font-weight: 400;\">. You have to process means, it has to be processed for a button bouncing. We will do that in the function process_button_pad_value. You send the btn_pad_value here\u2014software button debouncing code as shown below.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">The second task is to make an event. You have to compare that value. <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">If<\/span> btn_pad_value<span style=\"font-weight: 400;\">, the process_button_pad_value function returns a non-zero value if something is present on the button pad. So, let this function return a non-zero value if the button pad has been pressed or if any buttons of the button pad have been pressed. If the process_button_pad_value function returns 0, that means there is no activity on the button pad. So, no button has been pressed.&nbsp;&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">If no button is pressed, then the value is 0. That&#8217;s why we will process the btn_pad_value only if it is non-zero.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\"> Here, <\/span>if(btn_pad_value = BTN_PAD_VALUE_INC_TIME)<span style=\"font-weight: 400;\">. That means we have to send the Increment time event now.&nbsp;&nbsp;<\/span><\/span><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">We will create one event variable in the loop function, Protimer_user_event_t ue; (ue\u2013 user event).&nbsp;&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here,<\/span> ue.super.sig = INC_TIME; else if( btn_pad_value == BTN_PAD_VALUE_DEC_TIME<span style=\"font-weight: 400;\">), then you have to populate this signal variable with decrement time enumerator value. Like that you have to do. That&#8217;s how you make the event.&nbsp;<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And then here you send that event to the dispatcher. Send it to the event dispatcher&nbsp;\u2192 this is the third task. Protimer_event_dispatcher we have. We have to send the address of the main application object \u2018protimer\u2019 and the address of the user event. <\/span>Protimer_event_dispatcher(&amp;protimer, &amp;ue.super);<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And let\u2019s implement process_button_pad_value function now.&nbsp;&nbsp;<\/span><\/span><span style=\"color: #000000;\">uint8_t process_button_pad_value(uint8_t btn_pad_value)<span style=\"font-weight: 400;\">. And let\u2019s give the prototype; let\u2019s return 0 for the time being. This also, you can keep it static. We completed sending the user event.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Again, we have to implement some code to send the TICK event. So, we haven\u2019t implemented the code to dispatch the TICK event. We will see that in an upcoming article.&nbsp;&nbsp;<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #ff99cc;\">void<\/span> setup() {\r\n <span style=\"color: #008000;\"> \/\/ put your setup code here, to run once:<\/span>\r\n  protimer_init(&amp;protimer);\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> loop() {\r\n\r\n <span style=\"color: #008000;\"> uint8_t<\/span> b1,b2,b3,btn_pad_value;\r\n  protimer_user_event_t ue;\r\n  static uint32_t current_time = millis();\r\n  static protimer_tick_event_t te;\r\n\r\n <span style=\"color: #008000;\"> \/\/1. read the button pad status<\/span>\r\n  b1 = digitalRead(PIN_BUTTON1); \r\n  b2 = digitalRead(PIN_BUTTON2);\r\n  b3 = digitalRead(PIN_BUTTON3);\r\n\r\n  btn_pad_value = (b1&lt;&lt;2)|(b2&lt;&lt;1)|b3;\r\n\r\n<span style=\"color: #008000;\">  \/\/software button de-bouncing<\/span> \r\n  btn_pad_value = process_button_pad_value(btn_pad_value);\r\n\r\n<span style=\"color: #008000;\">  \/\/2. make an event<\/span> \r\n  <span style=\"color: #ff99cc;\">if<\/span>(btn_pad_value){\r\n  <span style=\"color: #ff99cc;\">if<\/span>(btn_pad_value == BTN_PAD_VALUE_INC_TIME){\r\n    ue.super.sig = INC_TIME;\r\n  }<span style=\"color: #ff99cc;\">else if<\/span>(btn_pad_value == BTN_PAD_VALUE_DEC_TIME){\r\n    ue.super.sig = DEC_TIME;\r\n  }<span style=\"color: #ff99cc;\">else if<\/span>(btn_pad_value == BTN_PAD_VALUE_SP){\r\n    ue.super.sig = START_PAUSE;\r\n  }<span style=\"color: #ff99cc;\">else if<\/span>(btn_pad_value == BTN_PAD_VALUE_ABRT){\r\n    ue.super.sig = ABRT;\r\n  }\r\n\r\n <span style=\"color: #008000;\"> \/\/3. send it to event dispatcher<\/span>\r\n  protimer_event_dispatcher(&amp;protimer,&amp;ue.super);\r\n<\/pre>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\">Event producer code<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 25px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">Click here:&nbsp;<\/span><span style=\"color: #3366ff;\"><a style=\"color: #3366ff;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\">https:\/\/fastbitlab.com\/course1<\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Exercise-003 Implementing event producer code &nbsp; &nbsp; In this article, first, we will provide a couple of macros for the pins; we haven&#8217;t given that. Let&#8217;s do that at the top in main.h as shown below. #define PIN_BUTTON1, which is 2. #define PIN_BUTTON2, which is 3, like that. PIN_BUTTON3&nbsp; to Arduino PIN 4, PIN_BUZZER [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7158,"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":"0","ocean_second_sidebar":"0","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":"0","ocean_custom_header_template":"0","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":"0","ocean_menu_typo_font_family":"0","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":"0","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":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[17],"class_list":["post-7153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-finite-state-machine","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>FSM Lecture 27: Exercise-003 Implementing event producer code<\/title>\n<meta name=\"description\" content=\"Exercise-003 Implementing event producer code. In this article, first, we will provide a couple of macros for the pins; we haven&#039;t given that.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FSM Lecture 27: Exercise-003 Implementing event producer code\" \/>\n<meta property=\"og:description\" content=\"Exercise-003 Implementing event producer code. In this article, first, we will provide a couple of macros for the pins; we haven&#039;t given that.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-07T07:58:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-08T10:35:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1803\" \/>\n\t<meta property=\"og:image:height\" content=\"777\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"FSM Lecture 27: Exercise-003 Implementing event producer code\",\"datePublished\":\"2022-02-07T07:58:31+00:00\",\"dateModified\":\"2023-08-08T10:35:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/\"},\"wordCount\":827,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Truth-table.png\",\"keywords\":[\"Finite state Machine(FSM)\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/\",\"name\":\"FSM Lecture 27: Exercise-003 Implementing event producer code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Truth-table.png\",\"datePublished\":\"2022-02-07T07:58:31+00:00\",\"dateModified\":\"2023-08-08T10:35:56+00:00\",\"description\":\"Exercise-003 Implementing event producer code. In this article, first, we will provide a couple of macros for the pins; we haven't given that.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Truth-table.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Truth-table.png\",\"width\":1803,\"height\":777,\"caption\":\"Figure 2. Truth table\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/exercise-003-implementing-event-producer-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FSM Lecture 27: Exercise-003 Implementing event producer code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FSM Lecture 27: Exercise-003 Implementing event producer code","description":"Exercise-003 Implementing event producer code. In this article, first, we will provide a couple of macros for the pins; we haven't given that.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/","og_locale":"en_US","og_type":"article","og_title":"FSM Lecture 27: Exercise-003 Implementing event producer code","og_description":"Exercise-003 Implementing event producer code. In this article, first, we will provide a couple of macros for the pins; we haven't given that.","og_url":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-02-07T07:58:31+00:00","article_modified_time":"2023-08-08T10:35:56+00:00","og_image":[{"width":1803,"height":777,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"FSM Lecture 27: Exercise-003 Implementing event producer code","datePublished":"2022-02-07T07:58:31+00:00","dateModified":"2023-08-08T10:35:56+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/"},"wordCount":827,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png","keywords":["Finite state Machine(FSM)"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/","url":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/","name":"FSM Lecture 27: Exercise-003 Implementing event producer code","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png","datePublished":"2022-02-07T07:58:31+00:00","dateModified":"2023-08-08T10:35:56+00:00","description":"Exercise-003 Implementing event producer code. In this article, first, we will provide a couple of macros for the pins; we haven't given that.","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Truth-table.png","width":1803,"height":777,"caption":"Figure 2. Truth table"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/exercise-003-implementing-event-producer-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"FSM Lecture 27: Exercise-003 Implementing event producer code"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=7153"}],"version-history":[{"count":4,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7153\/revisions"}],"predecessor-version":[{"id":15337,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7153\/revisions\/15337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/7158"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=7153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=7153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=7153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}