Marietjie Blignaut / Mbed 2 deprecated IceCreamMachine_

Dependencies:   mbed

Revision:
1:011f0bdaa7f5
Parent:
0:28f2dba63d6c
Child:
2:11714802a55d
--- a/main.cpp	Sun Jul 17 13:44:11 2022 +0000
+++ b/main.cpp	Sun Jul 17 18:07:55 2022 +0000
@@ -1,12 +1,12 @@
 /*----------------------------------------------------------
-State of a fictional IoT-enabled Ice cream machine
-The machine runs with an STM32F4 MCU; The Nucleo-F410RB was chosen as the device for implementation, it has serial communication, several digital outputs and 16 channel 12-bit ADC
+A fictional IoT-enabled Ice cream machine dispenser arm state
+The machine runs with an STM32F4 MCU; The Nucleo-F410RB is chosen for implementation, as it has serial communication, several digital outputs and 16 channel 12-bit ADC and more
 
-Operation: Ice cream dispenser arm sensor provides 0-3.3 V (assumed based on operating voltage 
+Operation: Ice cream machine dispenser arm sensor provides 0-3.3 V (assume based on operating voltage 
     of MCU) to one ADC pin on STM32F4 MCU. Voltage is based on position of dispenser arm. 
 - voltage > 1.65V implies the arm is pressed down 
 - voltage < 1.65V implies the arm is released 
-To prevent rapid switching, hysteresis is introduced with a count function, if arm has been pressed down for more than 5 seconds, the digital output will go high.
+To prevent rapid switching, hysteresis is introduced with a counter function, if arm is pressed down for more than 5 seconds, the digital output will go high.
 
 Requirements:
 1. Read ADC value and print over serial port
@@ -30,20 +30,20 @@
 #include "mbed.h"
 Ticker readADC;     //Allows timed interval of reading data on ADC lines
 
-//Serial pc(USBTX, USBRX); //default settings: 9600 8N1
+//Serial pc(USBTX, USBRX); 
 Serial device(D8, D2);  // tx, rx, default settings: 9600 8N1
 
 AnalogIn DispArmIn(A0); //ADC input from dispensing arm
 AnalogIn TempIn(A1);    //ADC input from temperature sensor
-AnalogIn LevelIn(A2);   // ADC input from sensor detecting level
+AnalogIn LevelIn(A2);   //ADC input from sensor detecting level
 
 float DispArm_data;     //Dispenser arm data
 float Temp_data;        //Temperature data
 float Level_data;       //Mixture level data
 bool ADC_ready;         //Indicate data has been read
-int counter;
+int counter;            //Hysteresis for dispenser arm
 
-DigitalOut dout(A4);  //Digital output to indicate if dispensing arm has crossed the halfway mark
+DigitalOut dout(A4);    //Digital output to indicate if dispensing arm has crossed the halfway mark
 DigitalOut led(LED2);   //Digital output for general use on LED
 
 void ReadAnalog()
@@ -53,14 +53,14 @@
     Temp_data  = TempIn;
     Level_data = LevelIn;
     
-    if (DispArm_data>0.5f) //Add hysteresis with count function, to prevent rapid switching
+    if (DispArm_data>0.5f) //Use counter function to prevent rapid switching
     {//Trigger output pin; Add this section here as it is one of the critical requirements.
         counter++;
         if(counter>5)
         { 
             dout = 1;  //Arm is pressed down
             counter=0;
-        } else{}
+        }
     }
     else {
          dout=0;    //Arm is released
@@ -77,7 +77,8 @@
     DispArm_data = 0.0;
     Temp_data  = 0.0;
     Level_data = 0.0;
-    readADC.attach(&ReadAnalog, 0.5);   // the address of the function to be attached and the interval (2 seconds)
+    
+    readADC.attach(&ReadAnalog, 0.5);   // the address of the function attached and the interval (0.5 seconds)
     device.printf("\nIce cream machine state:\n");
     
     while (1) {