MrPeanutcrackerful
Published

The Cool Coaster

This is a coaster that lets the user know when their drink is getting warm, so that they can ensure that they drink a cold beverage.

BeginnerShowcase (no instructions)237
The Cool Coaster

Story

Read more

Code

Coaster_Temp

C#
This uses the temperature sensor of the Adafruit Circuitboard Playground Express and records that as a variable. The code checks to see if that tempF variable is above or below 77 degrees Fahrenheit, if above then the LED Pixels on the board will shine Red indicating that the drink is warm. If below 77F, than the LED Pixels will shine blue, showing that the drink is cold. There is also a Potentiometer sensor that adjusts the brightness of the Pixels.
#include <Adafruit_CircuitPlayground.h>

float tempC, tempF;
int sensorPin=A3;
int sensorValue=0;

void setup() {
  Serial.begin(9600);
  CircuitPlayground.begin();
}

void loop() {
  tempC = CircuitPlayground.temperature();
  tempF = CircuitPlayground.temperatureF();

  sensorValue=analogRead(sensorPin)/4;
  if(sensorValue <=10){
    sensorValue=0;
  }

  CircuitPlayground.setBrightness(constrain(sensorValue,0,250));

  Serial.print("tempC: ");
  Serial.print(tempC);
  Serial.print("  tempF: ");
  Serial.println(tempF);


  

  if(tempF>=77)
  {
  CircuitPlayground.setPixelColor(0, 0xf83e4b);
  CircuitPlayground.setPixelColor(1, 0xf83e4b);
  CircuitPlayground.setPixelColor(2, 0xf83e4b);
  CircuitPlayground.setPixelColor(3, 0xf83e4b);
  CircuitPlayground.setPixelColor(4, 0xf83e4b);
  CircuitPlayground.setPixelColor(5, 0xf83e4b);
  CircuitPlayground.setPixelColor(6, 0xf83e4b);
  CircuitPlayground.setPixelColor(7, 0xf83e4b);
  CircuitPlayground.setPixelColor(8, 0xf83e4b);
  CircuitPlayground.setPixelColor(9, 0xf83e4b);
  
 
  }
  else
  {
  CircuitPlayground.setPixelColor(0, 0x0f0766);
  CircuitPlayground.setPixelColor(1, 0x0f0766);
  CircuitPlayground.setPixelColor(2, 0x0f0766);
  CircuitPlayground.setPixelColor(3, 0x0f0766);
  CircuitPlayground.setPixelColor(4, 0x0f0766);
  CircuitPlayground.setPixelColor(5, 0x0f0766);
  CircuitPlayground.setPixelColor(6, 0x0f0766);
  CircuitPlayground.setPixelColor(7, 0x0f0766);
  CircuitPlayground.setPixelColor(8, 0x0f0766);
  CircuitPlayground.setPixelColor(9, 0x0f0766);
    }
  

  delay(100);
}

Credits

MrPeanutcrackerful
4 projects • 0 followers

Comments