How to create pseudo code

How to create pseudo code for this code

#include <Stepper.h>
#include <Servo.h>
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"
#include "DFRobotDFPlayerMini.h"

VR myVR(10, 11);
DFRobotDFPlayerMini myDFPlayer;

uint8_t buf[64]; // Increased buffer size

const int stepsPerRevolution = 32;
const int buzzerPin = 17;
const int irSensorPin = A0;
const int servoPin = 2;
const int led1Pin = 35; // Define LED1 pin
const int led2Pin = 37; // Define LED2 pin
const int led3Pin = 31; // Define LED3 pin
const int led4Pin = 33; // Define LED4 pin
const int led5Pin = 27; // Define LED5 pin
const int led6Pin = 29; // Define LED6 pin
const int led7Pin = 23; // Define LED7 pin
const int led8Pin = 25; // Define LED8 pin

Servo servo;
int servoAngle = 0;
int NeozepCount = 0;      // Counter for "Neozep" commands
int BiogesicCount = 0;    // Counter for "Biogesic" commands
int ParacetamolCount = 0; // Counter for "Paracetamol" commands
int DecolgenCount = 0;    // Counter for "Decolgen" commands

Stepper myStepper1(stepsPerRevolution, 22, 26, 24, 28);
Stepper myStepper2(stepsPerRevolution, 30, 34, 32, 36);
Stepper myStepper3(stepsPerRevolution, 38, 42, 40, 44);
Stepper myStepper4(stepsPerRevolution, 46, 50, 48, 52);

#define NeozepRecord (8)
#define NeozepRecord (9)
#define BiogesicRecord (10)
#define NeozepRecord (11)
#define ParacetamolRecord (12)
#define ParacetamolRecord (13)
#define DecolgenRecord (14)

void setup() {
  Serial.begin(9600);
  Serial.println("Elechouse Voice Recognition V3 Module\r\nControl LED sample");

  Serial1.begin(9600);       // Initialize serial communication with DFPlayer Mini
  myDFPlayer.begin(Serial1); // Start communication with DFPlayer Mini
  delay(1000);               // Wait for DFPlayer Mini to initialize

  myVR.begin(9600);

  if (myVR.clear() == 0) {
    Serial.println("Recognizer cleared.");
  } else {
    Serial.println("Voice Recognition Module not found.");
    Serial.println("Please check the connection and restart Arduino.");
    while (1);
  }

  if (myVR.load((uint8_t)NeozepRecord) >= 0) {
    Serial.println("NeozepRecord loaded");
  }

  if (myVR.load((uint8_t)BiogesicRecord) >= 0) {
    Serial.println("Biogesic loaded");
  }

  if (myVR.load((uint8_t)ParacetamolRecord) >= 0) {
    Serial.println("Paracetamol loaded");
  }

  if (myVR.load((uint8_t)DecolgenRecord) >= 0) {
    Serial.println("Decolgen loaded");
  }

  pinMode(irSensorPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(servoPin, OUTPUT);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  pinMode(led6Pin, OUTPUT);
  pinMode(led7Pin, OUTPUT);
  pinMode(led8Pin, OUTPUT);

  // Initialize LED pins as outputs
  digitalWrite(led1Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led2Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led3Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led4Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led5Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led6Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led7Pin, LOW); // Turn off all LEDs initially
  digitalWrite(led8Pin, LOW); // Turn off all LEDs initially

  servo.attach(servoPin);
  myStepper1.setSpeed(1000);
  myStepper1.step(0);

  myStepper2.setSpeed(1000);
  myStepper2.step(0);

  myStepper3.setSpeed(1000);
  myStepper3.step(0);

  myStepper4.setSpeed(1000);
  myStepper4.step(0);
}

void loop() {
  int ret = myVR.recognize(buf, 50); // Adjust recognition threshold

  Serial.print("Voice Recognition Result: ");
  Serial.println(ret);

  if (ret > 0) {
    int sensorStatus; // Declare sensorStatus outside the switch statement
    switch (buf[1]) {
      case NeozepRecord:
        // Increment Neozep count
        NeozepCount++;
        Serial.print("Neozep count: ");
        Serial.println(NeozepCount);

        // Check if any medicine count is greater than or equal to 4
        if (NeozepCount < 4 && BiogesicCount < 4 && ParacetamolCount < 4 && DecolgenCount < 4) {
          // Play the first audio file
          myDFPlayer.play(1);
          delay(1000); // Wait for the first audio to finish playing
          // Rotate Stepper 1 clockwise
          myStepper1.setSpeed(1000);
          myStepper1.step(1024);
          delay(500);

          // Rotate the stepper motor back
          myStepper1.setSpeed(1000);
          myStepper1.step(-1024);

          // Trigger buzzer using IR sensor
          sensorStatus = digitalRead(irSensorPin);
          Serial.println("IR Sensor Status: " + String(sensorStatus)); // Debug print

          if (sensorStatus == LOW) {
            digitalWrite(buzzerPin, HIGH);
            delay(1000); // Increase the delay for a longer buzzer sound
            digitalWrite(buzzerPin, LOW);

            // Rotate the servo motor
            Serial.println("Rotating Servo to 90 degrees..."); // Debug print
            servo.write(45); // Rotate to 90 degrees (adjust as needed)
            delay(300);     // Adjust the delay based on your requirements

            Serial.println("Rotating Servo back to 0 degrees..."); // Debug print
            servo.write(0);  // Rotate back to 0 degrees

            // Play the second audio file
            myDFPlayer.play(2); // corrected file number
            delay(3000); // Wait for the second audio to finish playing

            // If "Neozep" is said two times, turn on the first LED
            if (NeozepCount == 2) {
              digitalWrite(led1Pin, HIGH); // Turn on the first LED
              // Play the third audio file
              myDFPlayer.play(3); // corrected file number
              delay(3000); // Wait for the third audio to finish playing
            }

            // If "Neozep" is said three times, turn on the second LED
            if (NeozepCount == 3) {
              digitalWrite(led1Pin, LOW); // Turn off the first LED
              digitalWrite(led2Pin, HIGH); // Turn on the second LED
              // Play the fourth audio file
              myDFPlayer.play(4); // corrected file number
              delay(3000); // Wait for the fourth audio to finish playing
            }
          }
        }
        break;

      case BiogesicRecord:
        // Increment Biogesic count
        BiogesicCount++;
        Serial.print("Biogesic count: ");
        Serial.println(BiogesicCount);

        // Check if any medicine count is greater than or equal to 4
        if (NeozepCount < 4 && BiogesicCount < 4 && ParacetamolCount < 4 && DecolgenCount < 4) {
          // Play the fifth audio file
          myDFPlayer.play(5);
          delay(1000); // Wait for the fifth audio to finish playing
          // Rotate Stepper 2 clockwise
          myStepper2.setSpeed(1000);
          myStepper2.step(1024);
          delay(500);

          // Rotate the stepper motor back
          myStepper2.setSpeed(1000);
          myStepper2.step(-1024);

          // Trigger buzzer using IR sensor
          sensorStatus = digitalRead(irSensorPin);
          Serial.println("IR Sensor Status: " + String(sensorStatus)); // Debug print

          if (sensorStatus == LOW) {
            digitalWrite(buzzerPin, HIGH);
            delay(1000); // Increase the delay for a longer buzzer sound
            digitalWrite(buzzerPin, LOW);

            // Rotate the servo motor
            Serial.println("Rotating Servo to 90 degrees..."); // Debug print
            servo.write(45); // Rotate to 90 degrees (adjust as needed)
            delay(300);     // Adjust the delay based on your requirements

            Serial.println("Rotating Servo back to 0 degrees..."); // Debug print
            servo.write(0);  // Rotate back to 0 degrees

            // Play the sixth audio file
            myDFPlayer.play(6); // corrected file number
            delay(3000); // Wait for the sixth audio to finish playing

            // If "Biogesic" is said two times, turn on the third LED
            if (BiogesicCount == 2) {
              digitalWrite(led3Pin, HIGH); // Turn on the third LED
              // Play the seventh audio file
              myDFPlayer.play(7); // corrected file number
              delay(3000); // Wait for the seventh audio to finish playing
            }

            // If "Biogesic" is said three times, turn on the fourth LED
            if (BiogesicCount == 3) {
              digitalWrite(led3Pin, LOW); // Turn off the third LED
              digitalWrite(led4Pin, HIGH); // Turn on the fourth LED
              // Play the eighth audio file
              myDFPlayer.play(8); // corrected file number
              delay(3000); // Wait for the eighth audio to finish playing
            }
          }
        }
        break;

      case ParacetamolRecord:
        // Increment Paracetamol count
        ParacetamolCount++;
        Serial.print("Paracetamol count: ");
        Serial.println(ParacetamolCount);

        // Check if any medicine count is greater than or equal to 4
        if (NeozepCount < 4 && BiogesicCount < 4 && ParacetamolCount < 4 && DecolgenCount < 4) {
          // Play the nineth audio file
          myDFPlayer.play(9);
          delay(1000); // Wait for the nineth audio to finish playing
          // Rotate Stepper 3 clockwise
          myStepper3.setSpeed(1000);
          myStepper3.step(1024);
          delay(500);

          // Rotate the stepper motor back
          myStepper3.setSpeed(1000);
          myStepper3.step(-1024);

          // Trigger buzzer using IR sensor
          sensorStatus = digitalRead(irSensorPin);
          Serial.println("IR Sensor Status: " + String(sensorStatus)); // Debug print

          if (sensorStatus == LOW) {
            digitalWrite(buzzerPin, HIGH);
            delay(1000); // Increase the delay for a longer buzzer sound
            digitalWrite(buzzerPin, LOW);

            // Rotate the servo motor
            Serial.println("Rotating Servo to 90 degrees..."); // Debug print
            servo.write(45); // Rotate to 90 degrees (adjust as needed)
            delay(300);     // Adjust the delay based on your requirements

            Serial.println("Rotating Servo back to 0 degrees..."); // Debug print
            servo.write(0);  // Rotate back to 0 degrees

            // Play the tenth audio file
            myDFPlayer.play(10); // corrected file number
            delay(3000); // Wait for the tenth audio to finish playing

            // If "Paracetamol" is said two times, turn on the fifth LED
            if (ParacetamolCount == 2) {
              digitalWrite(led5Pin, HIGH); // Turn on the fifth LED
              // Play the eleventh audio file
              myDFPlayer.play(11); // corrected file number
              delay(3000); // Wait for the eleventh audio to finish playing
            }

            // If "Paracetamol" is said three times, turn on the sixth LED
            if (ParacetamolCount == 3) {
              digitalWrite(led5Pin, LOW); // Turn off the fifth LED
              digitalWrite(led6Pin, HIGH); // Turn on the sixth LED
              // Play the twelfth audio file
              myDFPlayer.play(12); // corrected file number
              delay(3000); // Wait for the twelfth audio to finish playing
            }
          }
        }
        break;

      case DecolgenRecord:
        // Increment decolgen count
        DecolgenCount++;
        Serial.print("Decolgen count: ");
        Serial.println(DecolgenCount);

        // Check if any medicine count is greater than or equal to 4
        if (NeozepCount < 4 && BiogesicCount < 4 && ParacetamolCount < 4 && DecolgenCount < 4) {
          // Play the thirteenth audio file
          myDFPlayer.play(13);
          delay(1000); // Wait for the thirteenth audio to finish playing
          // Rotate Stepper 4 clockwise
          myStepper4.setSpeed(1000);
          myStepper4.step(1024);
          delay(500);

          // Rotate the stepper motor back
          myStepper4.setSpeed(1000);
          myStepper4.step(-1024);

          // Trigger buzzer using IR sensor
          sensorStatus = digitalRead(irSensorPin);
          Serial.println("IR Sensor Status: " + String(sensorStatus)); // Debug print

          if (sensorStatus == LOW) {
            digitalWrite(buzzerPin, HIGH);
            delay(1000); // Increase the delay for a longer buzzer sound
            digitalWrite(buzzerPin, LOW);

            // Rotate the servo motor
            Serial.println("Rotating Servo to 90 degrees..."); // Debug print
            servo.write(45); // Rotate to 90 degrees (adjust as needed)
            delay(300);     // Adjust the delay based on your requirements

            Serial.println("Rotating Servo back to 0 degrees..."); // Debug print
            servo.write(0);  // Rotate back to 0 degrees

            // Play the fourteenth audio file
            myDFPlayer.play(14); // corrected file number
            delay(3000); // Wait for the fourteenth audio to finish playing

            // If "delcolgen" is said two times, turn on the seventh LED
            if (DecolgenCount == 2) {
              digitalWrite(led7Pin, HIGH); // Turn on the seventh LED
              // Play the fifteenth audio file
              myDFPlayer.play(15); // corrected file number
              delay(3000); // Wait for the fifteenth audio to finish playing
            }

            // If "decolgen" is said three times, turn on the eight LED
            if (DecolgenCount == 3) {
              digitalWrite(led7Pin, LOW); // Turn off the seventh LED
              digitalWrite(led8Pin, HIGH); // Turn on the eighth LED
              // Play the sixteenth audio file
              myDFPlayer.play(16); // corrected file number
              delay(3000); // Wait for the second audio to finish playing
            }
          }
        }
        break;
    }
  }
}

Why do you want to? Is this for a code review, a user document, a coding manual, ??? They are different requirements.

2 Likes

google "writing pseudo code". You will find several hundred examples even one from the Girl Scouts of USA

ChatGPT - It can't write code, but it can fake it.

3 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.