Simple Web Scoreboard Example

From STEAMwiki
Jump to: navigation, search

This game "Shrek Pinball" was designed and built in a one day workshop by staff from the Toronto Public Library and the Peel Region School Board.

Shrek Pinball.jpg Shrek Pinball Team.jpg

HTML Scoreboard

https://thimbleprojects.org/dimentians/144007

You can edit the code directly by clicking on the "Remix" button in the upper right corner of the scoreboard. If you want to use this code with your own Particle Photon project, you will just have to change line 16 to include your Device ID and Authentication token instead of ours:

var sparkCore = new sparkControl("420032001147353236343033", "d8f9cf6fc5db1a15927cb262c1636f001ab21626");

Wiring

Connect the 64 pixel neopixel grid to pin D2.

Connect 6 light sensor circuits to pins A0 through A5.

Particle Arduino Code

Before pasting the Particle Arduino code into your project, include the neopixel library. The online particle code editor (IDE) doesn't automatically do this from the #include statements.

#include "neopixel/neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 64
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);


void setup() {
    pinMode(D7, OUTPUT);
    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    pinMode(A2, INPUT);
    pinMode(A3, INPUT);
    pinMode(A4, INPUT);
    pinMode(A5, INPUT);

    Serial.begin(9600);
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'

}

void loop() {
    
    // 3400 = bright lights
    // 2100 = covered with finger
    // 1100 = covered with phone
    
    // Debug code in case you need to calibrate the light sensors
    Serial.println(analogRead(A0));
    Serial.println(analogRead(A1));
    Serial.println(analogRead(A2));
    Serial.println(analogRead(A3));
    Serial.println(analogRead(A4));
    Serial.println(analogRead(A5));
    Serial.println("----");
        
    if (analogRead(A0) <  1800) {
        goodPoint();
    }
    else if (analogRead(A1) < 1800) {
        goodPoint();
    }
    else if (analogRead(A2) < 1800) {
        goodPoint();
    }
    
    else if (analogRead(A3) < 1800) {
        badPoint();
    }

    else if (analogRead(A4) < 1800) {
        badPoint();
    }
    else if (analogRead(A5) < 1800) {
        badPoint();
    }
  
    delay(5);
}

void goodPoint() {
    
    Particle.publish("Score", "0");
    for (int i=0; i<PIXEL_COUNT; i++) {
        strip.setPixelColor(i, 0, 40, 0);
    }
    strip.show();
    delay(1000);
    for (int i=0; i<PIXEL_COUNT; i++) {
        strip.setPixelColor(i, 0, 0, 0);
    }
    strip.show();
    delay(1000);
    Particle.publish("ScoreOff", "0");

}


void badPoint() {
    Particle.publish("Score", "1");
    for (int i=0; i<PIXEL_COUNT; i++) {
        strip.setPixelColor(i, 40, 0, 0);
    }
    strip.show();
    delay(1000);
    for (int i=0; i<PIXEL_COUNT; i++) {
        strip.setPixelColor(i, 0, 0, 0);
    }
    strip.show();
    delay(1000);
    Particle.publish("ScoreOff", "1");

}



<\pre>