HELP PLEASE! Annotating a piece of coding.

Hello, im a student and newbie i would like to ask for some help is possible. It is very urgent and i have 2 days left. I have a piece of coding that i do not undetsant very well. if possible can some please annotate the following code for me or explain how it works. Thank you.

Coffee_dispencer.ino (2.86 KB)

Please post you code this way.
Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Is any of this your work?

What parts are you having trouble with?

Hello, i am student and i am currently doing a project which have 2 days left. I am struggling wiht pseducode though i have made a code. im just not good with that stuff. if possible can some please turn my code into pesudocoding. thank you.

Coffee_dispencer.ino (2.86 KB)

It’s more usual to turn pseudo code into actual code.

Why not post your code?

Also here

People here do not like to be manipulated.

Yes this is the coding i have done, not all of it as some of it is example from my teacher. i have only done the setup section and the subroutines.

// include the library code:
#include <LiquidCrystal.h>

//Issues with the coding
//Motor does not respond

const int tempSensor = A0;
const int espresso=10, maxi=9, reset=8; //INPUT= User selection
const int greenLED=6, redLED=7; //OUTPUT= Indicate on/off
const int motorPump=13;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int drinkTemp=25;
//Variables will change:
int espressoS=0; 
int maxiS=0;
int resetS=0;
int count=0;

float temp=0;
void setup(){
  //LED pin used as an output:
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  //Motor used as output:
  pinMode(motorPump, OUTPUT);
  //Pushbuttons used as Inputs:
  pinMode(espresso, INPUT);
  pinMode(maxi, INPUT);
  pinMode(reset, INPUT);
  
  lcd.begin(16,2);
  //Print coffee slection message on LCD
  lcd.print("Select Coffee");
  digitalWrite(greenLED, HIGH);
}

void loop(){
  //Read status of the Pushbutton value:
  espressoS=digitalRead(espresso);
  maxiS=digitalRead(maxi);
  resetS=digitalRead(reset);
  
  //Confirming if Pushbutton has been pressed
  if (espressoS == HIGH){
    espressoCoffee();  
  } 
  else if (maxiS == HIGH){
    maxiCoffee();
  }
  
  else if (resetS==HIGH){
    
  }

}

void espressoCoffee(){
  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, LOW);
  LCDFirstRow("Espresso Coffee");
  
  while(temp<drinkTemp){
    readTemp();
    LCDSecondRow("Heating "+String(temp)+"*C");
    delay (1000);
  }
  
  for(int i=10;i>0;i--){
    motorPumpON();
    LCDSecondRow("Dispensing  "+String(i)+"s   ");
    delay(1000);
  }
  
  LCDFirstRow("Coffee is Ready");
  LCDSecondRow("Please remove");
  
  while (resetS !=1){
    resetS=digitalRead(reset);
    delay(10);
  }
  
  LCDSecondRow("                 ");
  LCDFirstRow("Select Coffee");

  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, HIGH);  
}

void maxiCoffee(){
  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, LOW);
  LCDFirstRow("Maxi Coffee");
  while(temp<drinkTemp){
    readTemp();
    LCDSecondRow("Heating "+String(temp)+"*C");
    delay(1000);
  }

  for(int i=10;i>0;i--){
    LCDSecondRow("Dispensing  "+String(i)+"s");
    delay(1000);
  }

  LCDFirstRow("Coffee is Ready");
  
  while (resetS !=1){
    resetS=digitalRead(reset);
    delay(10);
  }
  
  LCDSecondRow("                 ");
  LCDFirstRow("Select Coffee Pod");

  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, HIGH);  
}
  

void LCDFirstRow(String Message){
  lcd.setCursor(0, 0);
  lcd.print(Message);
}
  
void LCDSecondRow(String Message){
  lcd.setCursor(0, 1);
  lcd.print(Message);
}
  
void readTemp(){
  int reading=analogRead(tempSensor);
  float voltage=(reading/ 1024.0)*5.0;
  temp=(voltage-0.5)*100;
}

void motorPumpON(){
  digitalWrite(motorPump, HIGH);
}

void motorPumpOFF(){
  digitalWrite(motorPump, LOW);
}

What parts are you having trouble with understanding?

ahh sorry im not trying use anyone is just i really need a hand. but i will remove this topic sorry again.

mosh56:
ahh sorry im not trying use anyone is just i really need a hand. but i will ask a hard-working moderator to remove this topic sorry again.

The while and for loops

the following is part mine and my teachers example im just not sure how to convert it into psudocode.

// include the library code:
#include <LiquidCrystal.h>

//Issues with the coding
//Motor does not respond

const int tempSensor = A0;
const int espresso=10, maxi=9, reset=8; //INPUT= User selection
const int greenLED=6, redLED=7; //OUTPUT= Indicate on/off
const int motorPump=13;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int drinkTemp=25;
//Variables will change:
int espressoS=0; 
int maxiS=0;
int resetS=0;
int count=0;

float temp=0;
void setup(){
  //LED pin used as an output:
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  //Motor used as output:
  pinMode(motorPump, OUTPUT);
  //Pushbuttons used as Inputs:
  pinMode(espresso, INPUT);
  pinMode(maxi, INPUT);
  pinMode(reset, INPUT);
  
  lcd.begin(16,2);
  //Print coffee slection message on LCD
  lcd.print("Select Coffee");
  digitalWrite(greenLED, HIGH);
}

void loop(){
  //Read status of the Pushbutton value:
  espressoS=digitalRead(espresso);
  maxiS=digitalRead(maxi);
  resetS=digitalRead(reset);
  
  //Confirming if Pushbutton has been pressed
  if (espressoS == HIGH){
    espressoCoffee();  
  } 
  else if (maxiS == HIGH){
    maxiCoffee();
  }
  
  else if (resetS==HIGH){
    
  }

}

void espressoCoffee(){
  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, LOW);
  LCDFirstRow("Espresso Coffee");
  
  while(temp<drinkTemp){
    readTemp();
    LCDSecondRow("Heating "+String(temp)+"*C");
    delay (1000);
  }
  
  for(int i=10;i>0;i--){
    motorPumpON();
    LCDSecondRow("Dispensing  "+String(i)+"s   ");
    delay(1000);
  }
  
  LCDFirstRow("Coffee is Ready");
  LCDSecondRow("Please remove");
  
  while (resetS !=1){
    resetS=digitalRead(reset);
    delay(10);
  }
  
  LCDSecondRow("                 ");
  LCDFirstRow("Select Coffee");

  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, HIGH);  
}

void maxiCoffee(){
  digitalWrite(redLED, HIGH);
  digitalWrite(greenLED, LOW);
  LCDFirstRow("Maxi Coffee");
  while(temp<drinkTemp){
    readTemp();
    LCDSecondRow("Heating "+String(temp)+"*C");
    delay(1000);
  }

  for(int i=10;i>0;i--){
    LCDSecondRow("Dispensing  "+String(i)+"s");
    delay(1000);
  }

  LCDFirstRow("Coffee is Ready");
  
  while (resetS !=1){
    resetS=digitalRead(reset);
    delay(10);
  }
  
  LCDSecondRow("                 ");
  LCDFirstRow("Select Coffee Pod");

  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, HIGH);  
}
  

void LCDFirstRow(String Message){
  lcd.setCursor(0, 0);
  lcd.print(Message);
}
  
void LCDSecondRow(String Message){
  lcd.setCursor(0, 1);
  lcd.print(Message);
}
  
void readTemp(){
  int reading=analogRead(tempSensor);
  float voltage=(reading/ 1024.0)*5.0;
  temp=(voltage-0.5)*100;
}

void motorPumpON(){
  digitalWrite(motorPump, HIGH);
}

void motorPumpOFF(){
  digitalWrite(motorPump, LOW);
}

Read these links:

https://www.arduino.cc/reference/en/language/structure/control-structure/while/

https://www.arduino.cc/reference/en/language/structure/control-structure/for/

Does these help in your understanding?

in not sure on this

  for(int i=10;i>0;i--){

larryd:
What parts are you having trouble with understanding?

The concept that one should not cross-post?

mosh56:
in not sure on this

  for(int i=10;i>0;i--){

The variable ‘i’ is being created of ‘data type int’, it has an initial value of 10 at the opening { brace.

When code execution comes to the closing } brace, ‘i’ is decremented by 1.

If ‘i’ is greater that 0, execution returns to the opening { brace.

If ‘i’ is equal to 0 or less than 0, the code after the for() loop is executed, i.e we are finished with the for() loop.

As a result, the value of ‘i’ will be from ‘10 thru 1’ as execution loops around the for() loop.

Duplicate topics merged

@mosh56 - do not post duplicate questions. Answering them wastes time