PCOMP - Final 'Liiiiiiiiiiight'


For the final presentation

We changed the code so that when both of the users press hard enough, all of the panels light up and do a cycle to celebrate that they have won.





Arduino code:

// NeoPixel Ring simple sketch (c) 2013 Shae Erisson

// Released under the GPLv3 license to match the rest of the

// Adafruit NeoPixel library

#include <Adafruit_NeoPixel.h>

#ifdef AVR

#include <avr/power.h> // Required for 16 MHz Adafruit Trinket

#endif

// Which pin on the Arduino is connected to the NeoPixels?

#define PIN 6 // On Trinket or Gemma, suggest changing this to 1

// How many NeoPixels are attached to the Arduino?

#define NUMPIXELS 135 // Popular NeoPixel ring size

// When setting up the NeoPixel library, we tell it how many pixels,

// and which pin to use to send signals. Note that for older NeoPixel

// strips you might need to change the third parameter -- see the

// strandtest example for more information on possible values.

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 1000 // Time (in milliseconds) to pause between pixels

int bright1[] = {255, 255, 255, 255, 255, 255, 255, 255};

int bright2[] = {255, 255, 255, 255, 255, 255, 255, 255};

void setup() {

pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)

Serial.begin(9600);

}

void theaterChase(uint32_t color, int wait) {

for(int a=0; a<10; a++) { // Repeat 10 times...

for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...

pixels.clear(); // Set all pixels in RAM to 0 (off)

// 'c' counts up from 'b' to end of strip in steps of 3...

for(int c=b; c<pixels.numPixels(); c += 3) {

pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'

}

pixels.show(); // Update strip with new contents

delay(wait); // Pause for a moment

}

}

}

void colorWipe(uint32_t color, int wait) {

for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...

pixels.setPixelColor(i, color); // Set pixel's color (in RAM)

pixels.show(); // Update strip to match

delay(wait); // Pause for a moment

}

}

void colorWipe2(uint32_t color, int wait) {

for(int i=135; i>0; i--) { // For each pixel in strip...

pixels.setPixelColor(i, color); // Set pixel's color (in RAM)

pixels.show(); // Update strip to match

delay(wait); // Pause for a moment

}

}

void loop() {

// read the sensor on analog pin 0:

int sensorValue = analogRead(A0);

delay(1);

int sensorValue2 = analogRead(A2);

int ssValue = map(sensorValue, 0, 1023, 0, 900);

int ssValue2 = map(sensorValue2, 0, 1023, 0, 900);

Serial.println(ssValue);

Serial.println();

Serial.println(ssValue2);

//pixels.clear(); // Set all pixel colors to 'off'

// if sensor 2 pressed light

if (ssValue2 >= 0 && ssValue2 < 150) {

pixels.show();

// for(int i = 0 ; i < 7 ; i ++){

// bright1[i] = 0;

// }

//pixels.setBrightness(0);

for (int j = 63 ; j < 135 ; j++) {

pixels.setPixelColor(j, 0, 0, 0, 255);

}

}

if (ssValue >= 0 && ssValue < 100) {

pixels.show();

// for(int i = 0 ; i < 7 ; i ++){

// bright1[i] = 0;

// }

for (int i = 0 ; i < 72 ; i++) {

pixels.setPixelColor(i, 0, 0, 0, 0);

}

}

//1st

if (ssValue > 100) {

for (int i = -9 ; i < 9; i += 9) {

//bright1[0] = 255;

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 73, 252, 114, bright1[0]);

}

//pixels.setBrightness(255);

pixels.show();

}

}

//2nd

if (ssValue > 150) {

for (int i = 9 ; i < 18; i += 9) {

//bright1[0] = 255;

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 73, 252, 186, bright1[1]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//3rd

if (ssValue > 200) {

for (int i = 18 ; i < 27; i += 9) {

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 73, 252, 246, bright1[2]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//4th

if (ssValue > 250) {

for (int i = 27 ; i < 36; i += 9) {

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 73, 162, 252, bright1[3]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//5th

if (ssValue > 300) {

for (int i = 36 ; i < 45; i += 9) {

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 109, 73, 252, bright1[4]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//6th

if (ssValue > 350) {

for (int i = 45 ; i < 54; i += 9) {

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 182, 165, 252, bright1[5]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//7th

if (ssValue > 400) {

for (int i = 54 ; i < 63; i += 9) {

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 255, 255, 255, bright1[6]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//8th -mid

if (ssValue > 570 && ssValue2 > 600 ) {

//Serial.println(ssValue);

for (int i = 63 ; i < 72; i += 9) {

for (int j = 0 ; j < 9; j ++) {

pixels.setPixelColor(i + j, 255, 255, 255, bright1[7]);

}

pixels.setBrightness(255);

pixels.show();

// Do a theater marquee effect in white

theaterChase(pixels.Color(255, 255, 255), 50); // White, half brightness

colorWipe(pixels.Color(73, 252, 114), 50); // light green

colorWipe2(pixels.Color(189, 117, 252), 50); // pink

}

}

//15th

if (ssValue2 > 150) {

for (int i = 126 ; i < 136; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 255, 53, 161, bright2[0]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//14th

if (ssValue2 > 250) {

for (int i = 117 ; i < 126; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 255, 53, 93, bright2[1]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//13th

if (ssValue2 > 350) {

for (int i = 108 ; i < 117; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 255, 53, 161, bright2[2]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//12th

if (ssValue2 > 350) {

for (int i = 99 ; i < 108; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 253, 79, 230, bright2[3]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//11th

if (ssValue2 > 400) {

for (int i = 90 ; i < 99; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 242, 79, 253, bright2[4]);

}

pixels.show();

}

}

//10th

if (ssValue2 > 550) {

for (int i = 81 ; i < 90; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 222, 103, 252, bright2[5]);

}

pixels.setBrightness(255);

pixels.show();

}

}

//9th

if (ssValue2 > 600) {

for (int i = 72 ; i < 81; i += 9) {

for (int j = 0 ; j < 9; j++) {

pixels.setPixelColor(i + j, 189, 117, 252, bright2[6]);

}

pixels.setBrightness(255);

pixels.show();

}

}

}

 

©2019 by NOKJ. Proudly created with Wix.com