{"id":8764,"date":"2022-03-30T04:15:23","date_gmt":"2022-03-30T04:15:23","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=8764"},"modified":"2023-08-23T14:39:45","modified_gmt":"2023-08-23T09:09:45","slug":"fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/","title":{"rendered":"FSM Lecture 86| Exercise-008:Implementation part 5"},"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: #333399;\">Exercise-008:Implementation part 5<\/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=\"font-weight: 400; color: #000000;\">In this article, let&#8217;s code for main.c.&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;\">First, we will check the main.cpp. Here, we have to modify a couple of things.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #ff99cc;\">#include<\/span> &lt;Arduino.h&gt;\r\n<span style=\"color: #ff99cc;\">#include<\/span> \"qpn.h\"\r\n<span style=\"color: #ff99cc;\">#include<\/span> \"ClockAlarm_SM.h\"\r\n<span style=\"color: #ff99cc;\">#include<\/span> \"button_SM.h\"\r\n<span style=\"color: #ff99cc;\">#include<\/span> \"lcd.h\"\r\n<span style=\"color: #ff99cc;\">#include<\/span> \"main.h\"\r\n\r\nQ_DEFINE_THIS_FILE;\r\n\r\n<span style=\"color: #ff99cc;\">bool<\/span> flag_report_button_press = true;\r\n\r\n<span style=\"color: #ff99cc;\">static void<\/span> sys_tick_init(<span style=\"color: #ff99cc;\">void<\/span>);\r\n<span style=\"color: #ff99cc;\">static void<\/span> display_init(<span style=\"color: #ff99cc;\">void<\/span>);\r\n<span style=\"color: #ff99cc;\">static void<\/span> attach_button_interrupts(<span style=\"color: #ff99cc;\">void<\/span>);\r\n\r\n<span style=\"color: #ff99cc;\">static<\/span> QEvt ClockAlarmQueue[8];\r\n<span style=\"color: #ff99cc;\">static<\/span> QEvt ButtonQueue[8];\r\n\r\nQActiveCB const QF_active[] = {\r\n{ (QActive*) 0, (QEvt*) 0, 0},\r\n{ (QActive*) AO_ClockAlarm,(QEvt*)ClockAlarmQueue,Q_DIM(ClockAlarmQueue)},\r\n{ (QActive*) AO_Button,(QEvt*)ButtonQueue,Q_DIM(ButtonQueue)}\r\n};\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> setup() {\r\n<span style=\"color: #008000;\">\/\/ put your setup code here, to run once:<\/span>\r\nSerial.begin(9600);\r\ndisplay_init();\r\nattach_button_interrupts();\r\nClock_Alarm_ctor();\r\nButton_ctor();\r\nQF_init(Q_DIM(QF_active));\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> loop() {\r\nQF_run();\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> SET_handler(){\r\n\r\nQF_INT_DISABLE();\r\n<span style=\"color: #ff99cc;\">if<\/span>(flag_report_button_press){\r\nflag_report_button_press = false;\r\nQActive_armX(AO_Button,0,MS_TO_TICKS(50),0U);\r\n}\r\nQF_INT_ENABLE();\r\n\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> OK_handler(){\r\nQF_INT_DISABLE();\r\n<span style=\"color: #ff99cc;\">if<\/span>(flag_report_button_press){\r\nflag_report_button_press = false;\r\nQActive_armX(AO_Button,0,MS_TO_TICKS(50),0U);\r\n}\r\nQF_INT_ENABLE();\r\n}\r\n\r\n\r\n<span style=\"color: #ff99cc;\">static<\/span> void attach_button_interrupts(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\nattachInterrupt(digitalPinToInterrupt(PIN_BUTTON1), SET_handler, RISING);\r\nattachInterrupt(digitalPinToInterrupt(PIN_BUTTON2), OK_handler, RISING);\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">static void<\/span> sys_tick_init(<span style=\"color: #ff99cc;\">void<\/span>){\r\nTCCR1A = TCCR1A_CTC_MODE; <span style=\"color: #008000;\">\/\/CTC mode<\/span> \r\nTCCR1B = (TCCR1B_CTC_MODE |TCCR1B_PRESCALER_1); <span style=\"color: #008000;\">\/\/prescaler=1,CTC mode<\/span>\r\nTIMSK1 |= B00000010; <span style=\"color: #008000;\">\/\/Interrupt enable for OCR1A compare match<\/span>\r\nOCR1A = TIMER1_OC_MATCH_VALUE; <span style=\"color: #008000;\">\/\/OC match value for CONFIG_TICKS_PER_SECOND time base generation<\/span>\r\n}\r\n\r\n\r\n\r\n<span style=\"color: #ff99cc;\">static void<\/span> display_init(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\nlcd_begin(16,2);\r\nlcd_clear();\r\nlcd_move_cursor_L_to_R();\r\nlcd_set_cursor(0,0);\r\nlcd_no_auto_scroll();\r\nlcd_cursor_off();\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> QF_onStartup(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\nsys_tick_init();\r\n}\r\n\r\n<span style=\"color: #ff99cc;\">void<\/span> QV_onIdle(<span style=\"color: #ff99cc;\">void<\/span>){\r\nQV_CPU_SLEEP();\r\n}\r\n\r\nQ_NORETURN Q_onAssert ( char_t const Q_ROM *const module,int_t const location ){\r\nSerial.println(\"Assertion failure!!\");\r\nSerial.println((String)module);\r\nSerial.println(location);\r\n<span style=\"color: #ff99cc;\">while<\/span>(1);\r\n}<\/pre>\n<p class=\"\" style=\"text-align: center;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">main.cpp code<\/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;\">First of all, this button_pad_value function is not required now because we have a separate state machine for the button, and we&#8217;re also going to use button interrupts. That&#8217;s why the process_button_pad_value function is not required now. I am removing this whole function.<\/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;\">Q_onAssert function is required,&nbsp; display_init it is required, and a Timer1_setup is required, but we have to modify that. We will do that later.<\/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;\">In the loop function, we are going to delete everything. All these codes are not required because we are not sending the events like this. All events are delivered to the Event queues of the Active object asynchronously. Such a polling code is not required. I&#8217;m going to remove everything which is there in the loop function. Now the loop function is empty.&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;\">In the setup function, Serial.begin(9600) is required; a display_init is required. This&nbsp; QHSM_INIT is not required, so we will remove that. And after the display_init, we are calling the ctor of our Clock_Alarm class. But, we have two main classes in our project. Another one is the button class. That&#8217;s why we have to call the ctor of that as well.<\/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;\">For that, let&#8217;s add the header file at the top, #include &#8220;button_SM.h&#8221;. This file exposes Button_ctor function. <\/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;\">In the main.cpp, and after ClockAlarm_ctor, we will call this Button_ctor function, shown in above code.<\/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=\"font-weight: 400; color: #000000;\">And what we do in the Clock_Alarm_ctor, as you can see below, Clock_Alarm_ctor is a implementation, and it has one component.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">void<\/span> Clock_Alarm_ctor(<span style=\"color: #ff99cc;\">void<\/span>) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alarm_ctor(&amp;Clock_Alarm_obj.alarm);\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;QActive_ctor(AO_ClockAlarm,Q_STATE_CAST(&amp;Clock_Alarm_initial));\r\n}<\/pre>\n<div class=\"mceTemp\"><\/div>\n<p class=\"\" style=\"text-align: center;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">Clock_Alarm_ctor function<\/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;\">Now, this ctor should call the ctor of its components. That&#8217;s why, let&#8217;s call here the ctor of the component, that is alarm_ctor. And how is that exposed? That is exposed through the alarm.h.<\/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;\">Clock_Alarm_ctor is a container, and we will call the ctor of the component &#8216;Alarm_ctor().&#8217;&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;\">And for this, the Alarm_ctor function needs a pointer to the alarm class. That we can easily get from the object &#8216;&amp;Clock_Alarm_obj.alarm&#8217;. And this we shouldn&#8217;t be doing in this IDE because I cannot edit this here. That&#8217;s why I&#8217;m going to copy this code to the model.&nbsp;<\/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=\"font-weight: 400; color: #000000;\">In the model, I\u2019m pasting that code in Clock_Alarm_ctor. And save it, generate the code.<\/span><\/p>\n<figure id=\"attachment_8789\" aria-describedby=\"caption-attachment-8789\" style=\"width: 1252px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-8789 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1.png\" alt=\"Figure 5. 008ClockAlarm_AO project model\" width=\"1252\" height=\"451\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1.png 1252w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-300x108.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-768x277.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-1024x369.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-600x216.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-120x43.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-500x180.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-200x72.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-400x144.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-800x288.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/EmbeddedUMLStateMachines-1-1200x432.png 1200w\" sizes=\"(max-width: 1252px) 100vw, 1252px\" \/><figcaption id=\"caption-attachment-8789\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. 008ClockAlarm_AO project model<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">After that, when the Clock_Alarm_ctor gets called, it calls Alarm_ctor. And inside the Alarm_ctor, we initialize the state variable to Alarm_initial, which is the address of the initial state handler of the alarm state machine. (Figure 2)<\/span><\/p>\n<figure id=\"attachment_8771\" aria-describedby=\"caption-attachment-8771\" style=\"width: 1703px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-8771 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-6-32.png\" alt=\"Alarm_ctor function\" width=\"1703\" height=\"679\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32.png 1703w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-300x120.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-768x306.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-1024x408.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-600x239.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-120x48.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-500x199.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-200x80.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-400x159.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-800x319.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-6-32-1200x478.png 1200w\" sizes=\"(max-width: 1703px) 100vw, 1703px\" \/><figcaption id=\"caption-attachment-8771\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Alarm_ctor function<\/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;\">When you call the ctor of the Clock_Alarm class, that actually calls the ctor of all of its components. That&#8217;s how the Alarm_ctor gets called. And in the Alarm_ctor, we do QHsm_ctor. That is we call the ctor of the superclass. And the superclass of the Alarm class is QHsm. And you also know that this QHsm_ctor call initializes this Alarm_initial pointer or handler address to the state variable of the QHsm superclass.<\/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;\">After QHsm_ctor, you have to call QHsm_init, which executes the Alarm_initial function. That&#8217;s how the initial transition actions are executed.&nbsp;<\/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=\"font-weight: 400; color: #000000;\">Now,&nbsp; where to do QHsm_init? That you can do here.<\/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;\">Let&#8217;s go to the model. See Figure 3, this is our main state machine, the state machine of the Clock_Alarm, and there is an initial state transition.&nbsp;<\/span><\/p>\n<figure id=\"attachment_8772\" aria-describedby=\"caption-attachment-8772\" style=\"width: 1162px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-8772 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-7-30.png\" alt=\"008ClockAlarm_AO model\" width=\"1162\" height=\"635\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30.png 1162w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-300x164.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-768x420.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-1024x560.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-600x328.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-120x66.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-500x273.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-200x109.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-400x219.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-7-30-800x437.png 800w\" sizes=\"(max-width: 1162px) 100vw, 1162px\" \/><figcaption id=\"caption-attachment-8772\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. 008ClockAlarm_AO model<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">And from here, we will call the init function of the component. The component is the Alarm. We will create one function or an Alarm class operation. Right-click on Alarm and select Add Operation. I will name it as init, and the return type is void, visibility is public, and the code is you have to call QHSM_INIT from here.&nbsp;<\/span><\/p>\n<figure id=\"attachment_8773\" aria-describedby=\"caption-attachment-8773\" style=\"width: 1597px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8773 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-8-28.png\" alt=\"Creating an Alarm class operation\" width=\"1597\" height=\"645\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28.png 1597w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-300x121.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-768x310.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-1024x414.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-600x242.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-120x48.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-500x202.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-200x81.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-400x162.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-800x323.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-8-28-1200x485.png 1200w\" sizes=\"(max-width: 1597px) 100vw, 1597px\" \/><figcaption id=\"caption-attachment-8773\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Creating an Alarm class operation<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">For the QHSM_INIT, what are the arguments? You see, after QHsm_ctor, you have to call QHSM_INIT.<\/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;\">You have to mention the address of the superclass for this(me).<\/span><\/p>\n<figure id=\"attachment_8774\" aria-describedby=\"caption-attachment-8774\" style=\"width: 1136px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8774 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-9-26.png\" alt=\"QHSM_INIT API reference\" width=\"1136\" height=\"478\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26.png 1136w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-300x126.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-768x323.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-1024x431.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-600x252.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-120x50.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-500x210.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-200x84.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-400x168.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-9-26-800x337.png 800w\" sizes=\"(max-width: 1136px) 100vw, 1136px\" \/><figcaption id=\"caption-attachment-8774\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. QHSM_INIT API reference<\/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;\">Let&#8217;s go back to the model.&nbsp; And here in the code you write QHSM_Init, it is &amp;me-&gt; super.&nbsp; QHSM_Init code shown in Figure 4 you see.<\/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=\"font-weight: 400; color: #000000;\">After that, we will call this init function from the clock alarms initial transition from here, as shown in Figure 6.<\/span><\/p>\n<figure id=\"attachment_8775\" aria-describedby=\"caption-attachment-8775\" style=\"width: 1173px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8775 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-10-22.png\" alt=\"Alarm_init function\" width=\"1173\" height=\"335\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22.png 1173w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-300x86.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-768x219.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-1024x292.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-600x171.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-120x34.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-500x143.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-200x57.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-400x114.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-10-22-800x228.png 800w\" sizes=\"(max-width: 1173px) 100vw, 1173px\" \/><figcaption id=\"caption-attachment-8775\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Alarm_init function<\/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;\">Alarm_init(&amp;me-&gt;alarm);&nbsp; You can get the &#8216;me&#8217; pointer. Because the initial transition has access to the &#8216;me&#8217; pointer. You can generate the code.<\/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=\"font-weight: 400; color: #000000;\">Now you can see that in the alarm.h, there is a function Alarm_init, which will be called by this file ClockAlarm_SM.cpp.<\/span><\/p>\n<figure id=\"attachment_8776\" aria-describedby=\"caption-attachment-8776\" style=\"width: 1657px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8776 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-11-16.png\" alt=\"Implementation part 5\" width=\"1657\" height=\"893\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16.png 1657w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-300x162.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-768x414.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-1024x552.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-600x323.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-120x65.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-500x269.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-200x108.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-400x216.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-800x431.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-11-16-1200x647.png 1200w\" sizes=\"(max-width: 1657px) 100vw, 1657px\" \/><figcaption id=\"caption-attachment-8776\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. alarm.h file<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">Now, let&#8217;s go back to the main.cpp, and in the setup function, we have to call Button_ctor. After that, we have to implement the button interrupt handlers. Because we have to catch the button press via the interrupts. In the Arduino framework, you can easily implement the button interrupts. I mean, or the external interrupts. It&#8217;s very easy.<\/span><\/p>\n<figure id=\"attachment_8777\" aria-describedby=\"caption-attachment-8777\" style=\"width: 1689px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8777 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-12-13.png\" alt=\"Implementation part 5 button interrupts\" width=\"1689\" height=\"1025\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13.png 1689w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-300x182.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-768x466.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-1024x621.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-600x364.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-120x73.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-500x303.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-200x121.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-400x243.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-800x485.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-12-13-1200x728.png 1200w\" sizes=\"(max-width: 1689px) 100vw, 1689px\" \/><figcaption id=\"caption-attachment-8777\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. main.c, setup function<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">Let&#8217;s go to the Arduino home page and go to the reference. <\/span><\/p>\n<figure id=\"attachment_8778\" aria-describedby=\"caption-attachment-8778\" style=\"width: 1698px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8778 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-13-10.png\" alt=\"Implementation part 5 button interrupts\" width=\"1698\" height=\"822\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10.png 1698w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-300x145.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-768x372.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-1024x496.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-600x290.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-120x58.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-500x242.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-200x97.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-400x194.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-800x387.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-13-10-1200x581.png 1200w\" sizes=\"(max-width: 1698px) 100vw, 1698px\" \/><figcaption id=\"caption-attachment-8778\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Arduino home page<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">Here functions (as shown in Figure 10). Go to interrupts or you can go to external interrupts.<\/span><\/p>\n<figure id=\"attachment_8779\" aria-describedby=\"caption-attachment-8779\" style=\"width: 1570px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8779 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-14-9.png\" alt=\"Implementation part 5 button interrupts\" width=\"1570\" height=\"710\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9.png 1570w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-300x136.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-768x347.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-1024x463.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-600x271.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-120x54.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-500x226.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-200x90.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-400x181.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-800x362.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-14-9-1200x543.png 1200w\" sizes=\"(max-width: 1570px) 100vw, 1570px\" \/><figcaption id=\"caption-attachment-8779\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Functions<\/span><\/figcaption><\/figure>\n<p class=\"\" 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=\"color: #000000;\"><b>attachInterrupt()<\/b><span style=\"font-weight: 400;\"> \u2192&nbsp; By using this function, you can attach an interrupt. How to use this? It&#8217;s already mentioned here.<\/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 example, if you want to receive an interrupt on pin 2, then you have to use this attachInterrupt function. <\/span><b>attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE)<\/b><\/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;\">Mention the pin number, and mention the handler name. Here, the handler name is &#8216;blink .&#8217; When that interrupt happens, the blink function will get called.&nbsp;<\/span><\/p>\n<figure id=\"attachment_8780\" aria-describedby=\"caption-attachment-8780\" style=\"width: 1513px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8780 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-15-9.png\" alt=\"Implementation part 5 button interrupts\" width=\"1513\" height=\"883\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9.png 1513w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-300x175.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-768x448.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-1024x598.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-600x350.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-120x70.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-500x292.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-200x117.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-400x233.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-800x467.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-15-9-1200x700.png 1200w\" sizes=\"(max-width: 1513px) 100vw, 1513px\" \/><figcaption id=\"caption-attachment-8780\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Example code<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">And when should interrupts trigger? Whether it should trigger during the rising edge of the signal, a falling edge, or there are other options. Here it is (Figure 12).&nbsp;<\/span><\/p>\n<figure id=\"attachment_8781\" aria-describedby=\"caption-attachment-8781\" style=\"width: 1555px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8781 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-16-7.png\" alt=\"Implementation part 5\" width=\"1555\" height=\"819\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7.png 1555w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-300x158.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-768x404.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-1024x539.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-600x316.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-120x63.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-500x263.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-200x105.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-400x211.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-800x421.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-16-7-1200x632.png 1200w\" sizes=\"(max-width: 1555px) 100vw, 1555px\" \/><figcaption id=\"caption-attachment-8781\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Trigger<\/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;\">Trigger the interrupt whenever the pin is low, whenever the pin status changes, like that. We will go for RISING. Because, in our circuit, whenever the user presses a button, there will be a low to high transition. That&#8217;s why we will use RISING.<\/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;\">I&#8217;ll take the attachInterrupt<\/span><b>(digitalPinToInterrupt(interruptPin), blink, CHANGE) <\/b><span style=\"font-weight: 400;\">function and let&#8217;s go to our code.<\/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;\">In setup, I will write one function attach_button_interrupts() after the display init(). Let&#8217;s implement the attach_button_interrupts() function here.<\/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 we have to call this <\/span><b>attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE) <\/b><span style=\"font-weight: 400;\">&nbsp;function twice. And Change will be RISING. We will change blink as the OK handler and SET handler. And we will implement that function after the loop function.&nbsp; void SET_handler and another function will be the void OK_handler.&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=\"font-weight: 400; color: #000000;\">Here you have to mention PIN_BUTTON1 and PIN_BUTTON2.<\/span><\/p>\n<figure id=\"attachment_8782\" aria-describedby=\"caption-attachment-8782\" style=\"width: 1709px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8782 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-17-5.png\" alt=\"Implementation part 5\" width=\"1709\" height=\"929\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5.png 1709w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-300x163.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-768x417.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-1024x557.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-600x326.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-120x65.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-500x272.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-200x109.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-400x217.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-800x435.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-17-5-1200x652.png 1200w\" sizes=\"(max-width: 1709px) 100vw, 1709px\" \/><figcaption id=\"caption-attachment-8782\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 13. attach_button_interrupt function<\/span><\/figcaption><\/figure>\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=\"font-weight: 400; color: #000000;\">PIN_BUTTON1 and PIN_BUTTON2, these macros are there in main.h. PIN_BUTTON1 is our &#8216;SET&#8217; button, and&nbsp; PIN_BUTTON2 is the &#8216;OK&#8217; button.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 13px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">#define<\/span> PIN_BUTTON1 2 <span style=\"color: #008000;\">\/\/SET<\/span>\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_BUTTON2 3 <span style=\"color: #008000;\">\/\/OK<\/span>\r\n<span style=\"color: #ff99cc;\">#define<\/span> PIN_BUZZER 12<\/pre>\n<p class=\"\" style=\"text-align: center;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">main.h, PIN_BUTTON macros<\/span><\/p>\n<div class=\"mceTemp\"><\/div>\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=\"font-weight: 400; color: #000000;\">Let&#8217;s give the prototype here, as shown in figure 14.<\/span><\/p>\n<figure id=\"attachment_8784\" aria-describedby=\"caption-attachment-8784\" style=\"width: 1697px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8784 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/03\/Figure-19-2.png\" alt=\"Implementation part 5  button interrupts\" width=\"1697\" height=\"819\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2.png 1697w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-300x145.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-768x371.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-1024x494.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-600x290.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-120x58.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-500x241.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-200x97.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-400x193.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-800x386.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-19-2-1200x579.png 1200w\" sizes=\"(max-width: 1697px) 100vw, 1697px\" \/><figcaption id=\"caption-attachment-8784\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 14. attach_button_interrupts function prototype<\/span><\/figcaption><\/figure>\n<p class=\"\" 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;\">When the &#8216;SET&#8217; button is pressed, SET_handler will get called, so we have to post an event. We have to post an event to the event queue of the button active object.<\/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: 30px;\" 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;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Exercise-008:Implementation part 5 &nbsp; &nbsp; In this article, let&#8217;s code for main.c.&nbsp; First, we will check the main.cpp. Here, we have to modify a couple of things. #include &lt;Arduino.h&gt; #include &#8220;qpn.h&#8221; #include &#8220;ClockAlarm_SM.h&#8221; #include &#8220;button_SM.h&#8221; #include &#8220;lcd.h&#8221; #include &#8220;main.h&#8221; Q_DEFINE_THIS_FILE; bool flag_report_button_press = true; static void sys_tick_init(void); static void display_init(void); static void attach_button_interrupts(void); static [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8766,"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-8764","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>Implementing Button Interrupts for FSM: Part 5<\/title>\n<meta name=\"description\" content=\"Exercise-008:Implementation part 5. Learn how to implement button interrupts in an FSM-based Arduino project. This article guides you through\" \/>\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\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Implementing Button Interrupts for FSM: Part 5\" \/>\n<meta property=\"og:description\" content=\"Exercise-008:Implementation part 5. Learn how to implement button interrupts in an FSM-based Arduino project. This article guides you through\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/\" \/>\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-03-30T04:15:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-23T09:09:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-43.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1715\" \/>\n\t<meta property=\"og:image:height\" content=\"1039\" \/>\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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"FSM Lecture 86| Exercise-008:Implementation part 5\",\"datePublished\":\"2022-03-30T04:15:23+00:00\",\"dateModified\":\"2023-08-23T09:09:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/\"},\"wordCount\":1442,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-43.png\",\"keywords\":[\"Finite state Machine(FSM)\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/\",\"name\":\"Implementing Button Interrupts for FSM: Part 5\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-43.png\",\"datePublished\":\"2022-03-30T04:15:23+00:00\",\"dateModified\":\"2023-08-23T09:09:45+00:00\",\"description\":\"Exercise-008:Implementation part 5. Learn how to implement button interrupts in an FSM-based Arduino project. This article guides you through\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-43.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/Figure-1-43.png\",\"width\":1715,\"height\":1039,\"caption\":\"Figure 1. main.cpp code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FSM Lecture 86| Exercise-008:Implementation part 5\"}]},{\"@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":"Implementing Button Interrupts for FSM: Part 5","description":"Exercise-008:Implementation part 5. Learn how to implement button interrupts in an FSM-based Arduino project. This article guides you through","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\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/","og_locale":"en_US","og_type":"article","og_title":"Implementing Button Interrupts for FSM: Part 5","og_description":"Exercise-008:Implementation part 5. Learn how to implement button interrupts in an FSM-based Arduino project. This article guides you through","og_url":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-03-30T04:15:23+00:00","article_modified_time":"2023-08-23T09:09:45+00:00","og_image":[{"width":1715,"height":1039,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-43.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":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"FSM Lecture 86| Exercise-008:Implementation part 5","datePublished":"2022-03-30T04:15:23+00:00","dateModified":"2023-08-23T09:09:45+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/"},"wordCount":1442,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-43.png","keywords":["Finite state Machine(FSM)"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/","url":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/","name":"Implementing Button Interrupts for FSM: Part 5","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-43.png","datePublished":"2022-03-30T04:15:23+00:00","dateModified":"2023-08-23T09:09:45+00:00","description":"Exercise-008:Implementation part 5. Learn how to implement button interrupts in an FSM-based Arduino project. This article guides you through","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-43.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/03\/Figure-1-43.png","width":1715,"height":1039,"caption":"Figure 1. main.cpp code"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/fsm-lecture-86-exercise-008-implementation-part-5-button-interrupts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"FSM Lecture 86| Exercise-008:Implementation part 5"}]},{"@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\/8764","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=8764"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8764\/revisions"}],"predecessor-version":[{"id":15575,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/8764\/revisions\/15575"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/8766"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=8764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=8764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=8764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}