CCCPaste

Scanner rev_130

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Scanner
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-11-12 17:09:24
	- Source Code generated by: AlexWind

********* Pleasedontcode.com **********/

/********* User code review feedback **********
#### Feedback 1 ####
- complete the code
#### Feedback 2 ####
- everytime 'U' is received, so increase by 2 the percentage. Ever
y time 'D' is received, so decrease by 5 the percentage.
********* User code review feedback **********/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** SYSTEM REQUIREMENT 1 *****/
/* get hc05 signal and change PWM signal reducing */
/* percentage if receiving DOWN data or increasing */
/* percentage if receiving UP data. */

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t activation_PIN_D3 = 3;

/***** DEFINITION OF Software Serial *****/
const uint8_t bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
const uint8_t bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
SoftwareSerial bluetooth_HC05_mySerial(bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);

// Variable to store the current percentage
int percentage = 50;

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(activation_PIN_D3, OUTPUT);
  bluetooth_HC05_mySerial.begin(9600);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  // Read data from HC05 module
  if (bluetooth_HC05_mySerial.available()) {
    char data = bluetooth_HC05_mySerial.read();
    // Check if data is 'U' for UP or 'D' for DOWN
    if (data == 'U') {
      // Increase PWM signal percentage by 2
      percentage += 2;
      // Ensure the percentage does not exceed 100
      if (percentage > 100) {
        percentage = 100;
      }
    } else if (data == 'D') {
      // Decrease PWM signal percentage by 5
      percentage -= 5;
      // Ensure the percentage does not go below 0
      if (percentage < 0) {
        percentage = 0;
      }
    }
    // Calculate the duty cycle based on the percentage
    int dutyCycle = map(percentage, 0, 100, 0, 255);
    // Set the PWM signal
    analogWrite(activation_PIN_D3, dutyCycle);
  }
}