Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: RPM-based Lighting
- - Source Code compiled for: Arduino Nano
- - Source Code created on: 2024-03-13 10:58:19
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* neopixel should change color from green to red */
- /* smoothly with respecct to the calculated rpm using */
- /* hall sensor */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- #include <Adafruit_NeoPixel.h> //https://github.com/adafruit/Adafruit_NeoPixel
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- int calculateRPM();
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t button_DS18B20_DQ_PIN_D2 = 2;
- const uint8_t neoPixel_PIN = 6;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- DS18B20 ds18b20(button_DS18B20_DQ_PIN_D2);
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, neoPixel_PIN, NEO_GRB + NEO_KHZ800);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(button_DS18B20_DQ_PIN_D2, INPUT);
- strip.begin();
- strip.setBrightness(50);
- strip.show();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- int rpm = calculateRPM(); // Calculate RPM using hall sensor
- // Change color from green to red smoothly based on RPM
- for (int i = 0; i <= rpm; i++) {
- int red = map(i, 0, rpm, 0, 255);
- int green = map(i, 0, rpm, 255, 0);
- strip.fill(strip.Color(red, green, 0)); // Fill the strip with the calculated color
- strip.show();
- delay(10);
- }
- // Rest of the code
- }
- int calculateRPM() {
- // Code to calculate RPM using hall sensor
- // Replace with your actual implementation
- int rpm = 0;
- // Calculate RPM logic goes here
- return rpm;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement