Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include "serial.h"
#include "servo.h"
#include "functions.h"

class Smart_Segregator
	/*
	_____________________________________________________________
	|
	| Description
	| -----------
	| - This is a smart segregator which seperates dry and wet
	|   wet waste. (It cannot segregate metal or plastic)
	|
	|.............................................................
	|
	| Attributes
	| ----------
	| pin_1 : int
	|    -  Servo Motor pin number.
	|
	| pin_2 : int
	|    -  Moisture Sensor pin number.
	|
	| pin_3 : int
	|    - Touch Sensor pin number.
	|
	|............................................................
	|
	| Methods
	| -------
	| dry_waste()
	|       - Lid of the segregator slides towards right side.
	|
	| wet_waste()
	|       - Lid of the segregator slides towards left side
	|
	| neutral_state()
	|       - In which the lid of segregator is in the middle.
	|
	| execute()
	|       - Smart Segregator starts operating.
	|
	|___________________________________________________________
	*/
{
public:
	int servo_pin;
	int moisture_sensor_pin;
	int touch_sensor_pin;
	int detect_moisture;
	int detect_touch; 

	Servo servo;
	Serial serial;

	Smart_Segregator(int pin_1, int pin_2, int pin_3)
	{
		servo_pin = pin_1;
		moisture_sensor_pin = pin_2;
		touch_sensor_pin = pin_3;

		detect_moisture = 0;
		detect_touch = false;
	}

	void init()
	{
		serial.begin(9600);
		servo.attach(servo_pin);
		servo.write(90);

		pinMode(moisture_sensor_pin, INPUT);
		pinMode(touch_sensor_pin, INPUT);

		serial.println("Your Smart Segregator is ready to Segregate!");
	}

	void dry_waste()
	{
		servo.write(0);
	}

	void wet_waste()
	{
		servo.write(180);
	}

	void neutral_state()
	{
		servo.write(90);
	}

	void execute()
	{
		detect_moisture = analogRead(moisture_sensor_pin);
		detect_touch = digitalRead(touch_sensor_pin);

		if (detect_moisture > 85 && detect_touch == 1)
		{
			wet_waste();
		}

		else if (detect_moisture <= 85 && detect_touch == 1)
		{
			dry_waste();
		}

		else
		{
			neutral_state();
		}
	}
}

segregator = Smart_Segregator(8, 6, 2);

void setup()
{
	segregator.init();
}

void loop()
{
	segregator.execute();
}


What I have tried:

The code show error when complie
Posted
Updated 15-Apr-22 7:12am
v3
Comments
Richard MacCutchan 15-Apr-22 11:52am    
What error and where does it occur? Also, you need to format your code properly and add the correct <pre> tags around it. As posted it is difficult to understand.

1 solution

I've added pre tags to engage the syntax highlighter, and preserve your formatting (what there is of it)

Start by indenting your code so it's actually readable - at the moment it's pretty much impossible to tell what is going on, other than the first couple of bits of code are duplicated:
C++
#include <servo.h> class Smart_Segregator /* ... */ { public: int servo_pin; int moisture_sensor_pin; int touch_sensor_pin; int detect_moisture; int detect_touch; Servo servo; Smart_Segregator(int pin_1, int pin_2, int pin_3) { servo_pin = pin_1; moisture_sensor_pin = pin_2; touch_sensor_pin = pin_3; detect_moisture = 0; detect_touch = false; } void init() { Serial.begin(9600); servo.attach(servo_pin); servo.write(90); pinMode(moisture_sensor_pin, INPUT); pinMode(touch_sensor_pin, INPUT); Serial.println("Your Smart Segregator is ready to Segregate!"); } void dry_waste() { servo.write(0); } void wet_waste() { servo.write(180); } void neutral_state() { servo.write(90); } void execute() { detect_moisture =#include <servo.h>

class Smart_Segregator
So you have two classes called the same thing but the first one ends part way through a line of code...

THat looks like a copy'n'paste job gone very wrong - I'd start by thinking about what you do and don't need there and scrapping the dross before you even think about compiling.

If after that you still have compiler errors, this may help: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^]
 
Share this answer
 
Comments
merano99 15-Apr-22 13:27pm    
I would also accept your assumption that a copy'n'paste job went very wrong here. Someone who doesn't see this at first glance probably doesn't know exactly what he's actually doing. Apparently some lines of code have been duplicated and copied into each other. Nobody can read it like that. I removed the obvious duplicates and made small changes. The code looks like a typical Arduino program. Apparently other important information is missing as well.
Since we don't know exactly what the problem is, we can't go any further here without the author writing where exactly the problem is. After the rearrangement, the program can now be compiled without any problems...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900