The Alpha Geek – Geeking Out

Project #5: Lamps – Mk01

DonLuc1804Mk02.ino

// ***** Don Luc *****
// Software Version Information
// 1.01
// DonLuc1804Mk02 1.01
// Lamps

#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels
// Pin connected => 6
#define PIN 6
// How many NeoPixels are attached to the Arduino
// NUMPIXELS => 4
#define NUMPIXELS 4
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Panel Mount 1K potentiometer Bright
// Bright => A0
const int sensorBright = A0;
int sBright = 0;
int brightVal = 0;         // the sensor value
int brightMin = 0;        // minimum sensor value
int brightMax = 0;           // maximum sensor value
// Panel Mount 1K potentiometer
// Delay => A1
const int sensorDelay = A1;
long delayVal = 0;
// Rotary Switch - 10 Position
// Number => A2 (0 => 9)
const int sensorNumber = A2;
// Panel Mount 1K potentiometer
// Red - Led
const int sensorRed = 9;
int red = 0;
int redMin = 0;
int redMax = 0;
// Panel Mount 1K potentiometer
// Green - Led
const int sensorGreen = 8;
int green = 0;
int greenMin = 0;
int greenMax = 0;
// Panel Mount 1K potentiometer
// Blue - Led
const int sensorBlue = 7;
int blue = 0;
int blueMin = 0;
int blueMax = 0;
// variables:
//int x = 0;
int y = 0;
int z = 0;

void loop() {

  number();

}

bright.ino

void bright(){

    switch (sBright) {
        case 1:
            brightVal = 255;
            break;
         default:
            // read the sensor:
            brightVal = analogRead(sensorBright);
            // apply the calibration to the sensor reading
            brightVal = map(brightVal, brightMin, brightMax, 0, 255);        
            // in case the sensor value is outside the range seen during calibration
            brightVal = constrain(brightVal, 0, 255);
            break;
    }
  
}

iled.ino

void iled() {

   // red
   red = analogRead(sensorRed); 
   // apply the calibration to the sensor reading red
   red = map(red, redMin, redMax, 0, 255);
   // in case the sensor value is outside the range seen during calibration
   red = constrain(red, 0, 255);
   // green
   green = analogRead(sensorGreen); 
   // apply the calibration to the sensor reading red
   green = map(green, greenMin, greenMax, 0, 255);
   // in case the sensor value is outside the range seen during calibration
   green = constrain(green, 0, 255);
   // blue
   blue = analogRead(sensorBlue); 
   // apply the calibration to the sensor reading red
   blue = map(blue, blueMin, blueMax, 0, 255);
   // in case the sensor value is outside the range seen during calibration
   blue = constrain(blue, 0, 255);
                 
}

neopix.ino

void neopix() {
  
  for(int i=0; i<NUMPIXELS; i++){

    // bright
    bright();   
    pixels.setBrightness( brightVal );
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255    
    pixels.setPixelColor(i, pixels.Color(red,green,blue));
    // show
    pixels.show(); // This sends the updated pixel color to the hardware.
    // delay
    delay(50); // Delay for a period of time (in milliseconds).
    
  }
  
}

neopixt.ino

void neopixt() {
  
  for(int i=4; i<NUMPIXELS; i--){

    // bright
    bright();   
    pixels.setBrightness( brightVal );
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255    
    pixels.setPixelColor(i, pixels.Color(red,green,blue));
    // show
    pixels.show(); // This sends the updated pixel color to the hardware.
    // delay
    delay(50); // Delay for a period of time (in milliseconds).
    
  }
  
}

number.ino

void number(){

  z = analogRead(sensorNumber);
  y = (z / 127);

  sBright = 20000;
  
  // range value:
  switch (y) {
    case  0:
      // Led
      iled();
      // neopix
      neopix();
      // delay
      delayVal = (0);     
      break;
    case 1:
      // Led
      iled();
      // neopix
      neopix();
      // delay
      sdelay();
      break;
    case 2:
      // Led
      iled();
      // neopixt
      neopixt();
      // delay
      sdelay();
      break;
    case 3:
      // White
      red = 255;
      green = 255;
      blue = 255; 
      // neopix       
      neopix();
      // delay
      delayVal = (0);
      break;  
    case 4:
      // Green
      red = 0;
      green = 255;
      blue = 0;
      // neopix        
      neopix();
      // delay
      delayVal = (0);
      break;
    case 5:
      // Red
      red = 255;
      green = 0;
      blue = 0;        
      // neopix        
      neopix();
      // delay
      delayVal = (0);
      break;
    case 6:
      // White
      red = 255;
      green = 255;
      blue = 255; 
      // neopix       
      neopix();
      // delay
      sdelay();
      break;       
    case 7:
      // Green
      red = 0;
      green = 255;
      blue = 0; 
      // neopix       
      neopix();
      // delay
      sdelay();
      break; 
    case 8:
      // Red
      red = 255;
      green = 0;
      blue = 0; 
      // neopix       
      neopix();
      // delay
      sdelay();
      break; 
    case 9:

      break;
  }
  
}

sdelay.ino

void sdelay() {

    delayVal = analogRead(sensorDelay);
    delayVal = (250 * delayVal);
      
}

setup.ino

void setup() {
  
    pixels.begin(); // This initializes the NeoPixel library.
    
}

Don Luc

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories
Archives