Advertisement
pleasedontcode

Scanner rev_130

Nov 12th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Scanner
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-12 17:09:24
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - complete the code
  22. #### Feedback 2 ####
  23. - everytime 'U' is received, so increase by 2 the percentage. Ever
  24. y time 'D' is received, so decrease by 5 the percentage.
  25. ********* User code review feedback **********/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29. #include <SoftwareSerial.h>
  30.  
  31. /****** SYSTEM REQUIREMENT 1 *****/
  32. /* get hc05 signal and change PWM signal reducing */
  33. /* percentage if receiving DOWN data or increasing */
  34. /* percentage if receiving UP data. */
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39.  
  40. /***** DEFINITION OF PWM OUTPUT PINS *****/
  41. const uint8_t activation_PIN_D3 = 3;
  42.  
  43. /***** DEFINITION OF Software Serial *****/
  44. const uint8_t bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  45. const uint8_t bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  46. SoftwareSerial bluetooth_HC05_mySerial(bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);
  47.  
  48. // Variable to store the current percentage
  49. int percentage = 50;
  50.  
  51. void setup(void)
  52. {
  53.   // put your setup code here, to run once:
  54.   pinMode(activation_PIN_D3, OUTPUT);
  55.   bluetooth_HC05_mySerial.begin(9600);
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // put your main code here, to run repeatedly:
  61.   // Read data from HC05 module
  62.   if (bluetooth_HC05_mySerial.available()) {
  63.     char data = bluetooth_HC05_mySerial.read();
  64.     // Check if data is 'U' for UP or 'D' for DOWN
  65.     if (data == 'U') {
  66.       // Increase PWM signal percentage by 2
  67.       percentage += 2;
  68.       // Ensure the percentage does not exceed 100
  69.       if (percentage > 100) {
  70.         percentage = 100;
  71.       }
  72.     } else if (data == 'D') {
  73.       // Decrease PWM signal percentage by 5
  74.       percentage -= 5;
  75.       // Ensure the percentage does not go below 0
  76.       if (percentage < 0) {
  77.         percentage = 0;
  78.       }
  79.     }
  80.     // Calculate the duty cycle based on the percentage
  81.     int dutyCycle = map(percentage, 0, 100, 0, 255);
  82.     // Set the PWM signal
  83.     analogWrite(activation_PIN_D3, dutyCycle);
  84.   }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement