Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TMP36 Pin Variables
- int temperaturePin = 0; //input: the analog pin the TMP36 is connected
- //RGB LED pins
- int ledDigitalOne[] = {9, 10, 11}; //output: the three digital pins of the RGB LED
- //9 = redPin, 10 = greenPin, 11 = bluePin
- const boolean ON = LOW;
- const boolean OFF = HIGH;
- //Predefined Colors
- const boolean RED[] = {ON, OFF, OFF};
- const boolean GREEN[] = {OFF, ON, OFF};
- const boolean BLUE[] = {OFF, OFF, ON};
- const boolean YELLOW[] = {ON, ON, OFF};
- const boolean CYAN[] = {OFF, ON, ON};
- const boolean MAGENTA[] = {ON, OFF, ON};
- const boolean WHITE[] = {ON, ON, ON};
- const boolean BLACK[] = {OFF, OFF, OFF};
- void setup()
- {
- for (int i = 0; i < 3; i++) {
- pinMode(ledDigitalOne[i], OUTPUT); //Set the RGB LED pins as outputs
- }
- Serial.begin(9600); //Start the serial connection with the computer
- }
- void loop()
- {
- float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
- temperature = (((temperature - .5) * 100) * 1.8) + 32; //converting from 10 mv per degree wit 500 mV offset
- int newTemperature = temperature; //to degrees ((volatge β 500mV) times 100)
- Serial.println(newTemperature); //printing the result
- delay(7000); //waiting 7 seconds to get a new result
- // Set the three LEDs to any predefined color depending of the temperature in ΒΊF
- if ((newTemperature > 40) && (newTemperature <= 71)) {
- setColor(ledDigitalOne, BLACK);
- Serial.println("Black");
- }
- else if ((newTemperature >= 72) && (newTemperature <= 73)) {
- setColor(ledDigitalOne, WHITE);
- Serial.println("White");
- }
- else if ((newTemperature >= 74) && (newTemperature <= 75)) {
- setColor(ledDigitalOne, GREEN);
- Serial.println("Green");
- }
- else if ((newTemperature >= 76) && (newTemperature <= 77)) {
- setColor(ledDigitalOne, CYAN);
- Serial.println("Cyan");
- }
- else if ((newTemperature >= 78) && (newTemperature <= 79)) {
- setColor(ledDigitalOne, BLUE);
- Serial.println("Blue");
- }
- else if ((newTemperature >= 80) && (newTemperature <= 81)) {
- setColor(ledDigitalOne, YELLOW);
- Serial.println("Yellow");
- }
- else if ((newTemperature >= 82) && (newTemperature <= 83)) {
- setColor(ledDigitalOne, RED);
- Serial.println("Red");
- }
- else {
- setColor(ledDigitalOne, MAGENTA);
- Serial.println("Magenta");
- }
- }
- float {getVoltage(int pin) {
- return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
- // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
- }}
- // Function to set the color
- void {setColor(int* led, boolean * color) {
- for (int i = 0; i < 3; i++) {
- digitalWrite(led[i], color[i]);
- }
- }
- }
- // A version of setColor that allows for using const boolean colors
- void setColor(int* led, const boolean* color) {
- boolean tempColor[] = {color[0], color[1], color[2]};
- setColor(led, tempColor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement