Advertisement
pleasedontcode

RPM-based Lighting rev_01

Mar 13th, 2024
86
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: RPM-based Lighting
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-03-13 10:58:19
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* neopixel should change color from green to red */
  21.     /* smoothly with respecct to the calculated rpm using */
  22.     /* hall sensor */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  27. #include <Adafruit_NeoPixel.h>    //https://github.com/adafruit/Adafruit_NeoPixel
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. int calculateRPM();
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t button_DS18B20_DQ_PIN_D2  = 2;
  36. const uint8_t neoPixel_PIN = 6;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. DS18B20 ds18b20(button_DS18B20_DQ_PIN_D2);
  40. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, neoPixel_PIN, NEO_GRB + NEO_KHZ800);
  41.  
  42. void setup(void)
  43. {
  44.     // put your setup code here, to run once:
  45.     pinMode(button_DS18B20_DQ_PIN_D2, INPUT);
  46.  
  47.     strip.begin();
  48.     strip.setBrightness(50);
  49.     strip.show();
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // put your main code here, to run repeatedly:
  55.     int rpm = calculateRPM();  // Calculate RPM using hall sensor
  56.  
  57.     // Change color from green to red smoothly based on RPM
  58.     for (int i = 0; i <= rpm; i++) {
  59.         int red = map(i, 0, rpm, 0, 255);
  60.         int green = map(i, 0, rpm, 255, 0);
  61.         strip.fill(strip.Color(red, green, 0));  // Fill the strip with the calculated color
  62.         strip.show();
  63.         delay(10);
  64.     }
  65.  
  66.     // Rest of the code
  67. }
  68.  
  69. int calculateRPM() {
  70.     // Code to calculate RPM using hall sensor
  71.     // Replace with your actual implementation
  72.     int rpm = 0;
  73.  
  74.     // Calculate RPM logic goes here
  75.  
  76.     return rpm;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement