Advertisement
pleasedontcode

**LED Control** rev_01

Oct 30th, 2024
51
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: **LED Control**
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-10-30 22:02:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* I keep getting the error code "expected '(' before */
  21.     /* 'val'", Does anyone know what that means and how */
  22.     /* to fix it? */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #define red 4
  29. #define blue 3
  30. #define yellow 2
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. void setup(void)
  37. {
  38.     // put your setup code here, to run once:
  39.     pinMode(red, OUTPUT);
  40.     pinMode(blue, OUTPUT);
  41.     pinMode(yellow, OUTPUT);
  42. }
  43.  
  44. void loop(void)
  45. {
  46.     // put your main code here, to run repeatedly:
  47.     int val = digitalRead(A0);
  48.    
  49.     // Corrected syntax for the following conditions:
  50.     if (val <= 341) {
  51.         digitalWrite(red, HIGH);
  52.     } else {
  53.         digitalWrite(red, LOW); // Ensure the LED is turned off when val > 341
  54.     }
  55.  
  56.     if (val >= 682) {
  57.         digitalWrite(red, HIGH);
  58.         digitalWrite(blue, HIGH);
  59.     } else {
  60.         digitalWrite(blue, LOW); // Ensure the LED is turned off when val < 682
  61.     }
  62.  
  63.     if (val >= 1023) {
  64.         digitalWrite(red, HIGH);
  65.         digitalWrite(blue, HIGH);
  66.         digitalWrite(yellow, HIGH);
  67.     } else {
  68.         digitalWrite(yellow, LOW); // Ensure the LED is turned off when val < 1023
  69.     }
  70. }
  71.  
  72. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement