Advertisement
pleasedontcode

LED Control rev_02

Oct 30th, 2024
75
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 compiled for: Arduino Mega
  14.     - Source Code created on: 2024-10-30 22:04:46
  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.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #define red 4
  30. #define blue 3
  31. #define yellow 2
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. void setup(void)
  38. {
  39.     // put your setup code here, to run once:
  40.     pinMode(red, OUTPUT);
  41.     pinMode(blue, OUTPUT);
  42.     pinMode(yellow, OUTPUT);
  43. }
  44.  
  45. void loop(void)
  46. {
  47.     // put your main code here, to run repeatedly:
  48.     int val = digitalRead(A0);
  49.    
  50.     // Corrected syntax for the following conditions:
  51.     if (val <= 341) {
  52.         digitalWrite(red, HIGH);
  53.     } else {
  54.         digitalWrite(red, LOW); // Ensure the LED is turned off when val > 341
  55.     }
  56.  
  57.     if (val >= 682) {
  58.         digitalWrite(red, HIGH);
  59.         digitalWrite(blue, HIGH);
  60.     } else {
  61.         digitalWrite(blue, LOW); // Ensure the LED is turned off when val < 682
  62.     }
  63.  
  64.     if (val >= 1023) {
  65.         digitalWrite(red, HIGH);
  66.         digitalWrite(blue, HIGH);
  67.         digitalWrite(yellow, HIGH);
  68.     } else {
  69.         digitalWrite(yellow, LOW); // Ensure the LED is turned off when val < 1023
  70.     }
  71. }
  72.  
  73. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement