Skip to content

Instantly share code, notes, and snippets.

@natendaben
Created October 4, 2018 16:42
Show Gist options
  • Save natendaben/2cae9f8c944daa441cb3293ab404a68c to your computer and use it in GitHub Desktop.
Save natendaben/2cae9f8c944daa441cb3293ab404a68c to your computer and use it in GitHub Desktop.
Lab 3 Part 3
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
//pin that the strip is connected to
#define PIN 13
//first argument is # pixels - change to how many you have
Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, PIN, NEO_GRB + NEO_KHZ800);
int pot1 = 0;
int pot2 = 0;
int col1 = 30;
int col2 = 30;
int col3 = 30;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(13, OUTPUT);
strip.begin();
strip.show();
}
void loop() {
// put your main code here, to run repeatedly:
pot1 = analogRead(A0);
pot2 = analogRead(A1);
//Serial.print("Pot 1: ");
//Serial.println(pot1);
Serial.print("Pot 2: ");
Serial.println(pot2);
if(pot2>992)
{
col1 = 255;
col2 = 0;
col3 = 0;
}
if(pot2<=992 && pot2>960)
{
col1 = 255;
col2 = 72;
col3 = 0;
}
if(pot2<=960 && pot2>928)
{
col1 = 255;
col2 = 110;
col3 = 0;
}
if(pot2<=928 && pot2>896)
{
col1 = 255;
col2 = 161;
col3 = 0;
}
if(pot2<=896 && pot2>864)
{
col1 = 255;
col2 = 208;
col3 = 0;
}
if(pot2<=864 && pot2>832)
{
col1 = 255;
col2 = 246;
col3 = 0;
}
if(pot2<=832 && pot2>800)
{
col1 = 233;
col2 = 255;
col3 = 0;
}
if(pot2<=768 && pot2>736)
{
col1 = 204;
col2 = 255;
col3 = 0;
}
if(pot2<=736 && pot2>704)
{
col1 = 157;
col2 = 255;
col3 = 0;
}
if(pot2<=704 && pot2>672)
{
col1 = 106;
col2 = 255;
col3 = 0;
}
if(pot2<=672 && pot2>640)
{
col1 = 46;
col2 = 255;
col3 = 0;
}if(pot2<=640 && pot2>608)
{
col1 = 0;
col2 = 255;
col3 = 46;
}
if(pot2<=608 && pot2>576)
{
col1 = 0;
col2 = 255;
col3 = 161;
}
if(pot2<=576 && pot2>544)
{
col1 = 0;
col2 = 255;
col3 = 242;
}
if(pot2<=544 && pot2>512)
{
col1 = 0;
col2 = 204;
col3 = 255;
}
if(pot2<=512 && pot2>480)
{
col1 = 0;
col2 = 169;
col3 = 255;
}
if(pot2<=480 && pot2>448)
{
col1 = 0;
col2 = 135;
col3 = 255;
}
if(pot2<=448 && pot2>416)
{
col1 = 0;
col2 = 85;
col3 = 255;
}
if(pot2<=416 && pot2>384)
{
col1 = 0;
col2 = 33;
col3 = 255;
}
if(pot2<=384 && pot2>352)
{
col1 = 21;
col2 = 0;
col3 = 255;
}
if(pot2<=352 && pot2>320)
{
col1 = 60;
col2 = 0;
col3 = 255;
}
if(pot2<=320 && pot2>288)
{
col1 = 97;
col2 = 0;
col3 = 255;
}
if(pot2<=288 && pot2>256)
{
col1 = 152;
col2 = 0;
col3 = 255;
}
if(pot2<=256 && pot2>224)
{
col1 = 178;
col2 = 0;
col3 = 255;
}
if(pot2<=224 && pot2>192)
{
col1 = 216;
col2 = 0;
col3 = 255;
}
if(pot2<=192 && pot2>160)
{
col1 = 246;
col2 = 0;
col3 = 255;
}
if(pot2<=160 && pot2>128)
{
col1 = 255;
col2 = 0;
col3 = 220;
}
if(pot2<=128 && pot2>96)
{
col1 = 255;
col2 = 0;
col3 = 170;
}
if(pot2<=96 && pot2>64)
{
col1 = 255;
col2 = 0;
col3 = 119;
}
if(pot2<=64 && pot2>32)
{
col1 = 255;
col2 = 0;
col3 = 80;
}
if(pot2<=32)
{
col1 = 255;
col2 = 0;
col3 = 34;
}
if(pot1>900)
{
strip.setPixelColor(0, 0, 0, 0);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
}
if(pot1<=900)
{
strip.setPixelColor(0, col1, col2, col3);
strip.setPixelColor(1, 0, 0, 0);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
}
if(pot1<=700)
{
strip.setPixelColor(1, col1, col2, col3);
strip.setPixelColor(2, 0, 0, 0);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
}
if(pot1<=400)
{
strip.setPixelColor(2, col1, col2, col3);
strip.setPixelColor(3, 0, 0, 0);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
}
if(pot1<=250)
{
strip.setPixelColor(3, col1, col2, col3);
strip.setPixelColor(4, 0, 0, 0);
strip.show();
}
if(pot1<=100)
{
strip.setPixelColor(4, col1, col2, col3);
strip.show();
}
//Serial.print("Pot 2: ");
//Serial.println(pot2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment