Simple implementation of goal counter for table football using laser diode and phototransistor.

Dependencies:   GoalCounter WS2812 PixelArray

main.cpp

Committer:
nxf46245
Date:
2019-01-10
Revision:
0:24f846b68c77
Child:
1:ffac56d434b3

File content as of revision 0:24f846b68c77:

#include "mbed.h"
#include "WS2812.h"
#include "PixelArray.h"
#include "GoalCounter.h"

#define WS2812_BUF 10
#define NUM_COLORS 1
#define NUM_LEDS_PER_COLOR 2
#define COLOR 0x2f2020 

// Initialize instace of a pixel array for LED strip
PixelArray px(WS2812_BUF);

// The given numbers are for the K64F MCU
WS2812 ws(D4, WS2812_BUF, 0, 5, 5, 0);
GoalCounter gc(D2);

//// Detector for the 
//InterruptIn detector1(D3);
//InterruptIn detector2(D2);
//
//DigitalOut led1(LED1);
//DigitalOut led2(LED2);
//
//Timer t;
Serial pc(USBTX, USBRX);
//
float balltime = 0;
float speed = 0;
uint8_t score_1 = 0;
//
void print_time() {
   pc.printf("The time taken was %f microseconds\n", balltime);     
}
//
//void tstart() {
//    t.start();
//}
//
//void tstop() {
//    t.stop();
//    balltime = t.read();
//    t.reset();
//}
//
//void set_score(uint8_t score) {
//    for (int i=0; i < score; i++) {
//        px.Set(i, COLOR);
//    }
//    for (int i = score; i <= 10; i++) {
//        px.Set(i, 0);        
//    }
//    
//    px.SetAllI(0x0f);
////    ws.write_offsets(px.getBuf(),0,0,0);
//    ws.write(px.getBuf()); 
//}

int main()
{
    // Optional: set mode as PullUp/PullDown/PullNone/OpenDrain
    //mypin.mode(PullNone); 
//    
//    detector1.fall(&tstart);
//    detector2.rise(&tstop);
    
    ws.useII(WS2812::GLOBAL); // use global intensity scaling
    
    while(1) {
        
       // if (balltime != 0) {
//            pc.printf("Time of ball pass : %f seconds\n\r", balltime);
//            float speed = 0.035/balltime*3.6;
//            pc.printf("Speed of ball (3.5 cm diameter) : %f kph\n\r", speed);
//            
//            score_1++;
//            
//            if (score_1 > 10)
//                score_1 = 0;
//                
//            set_score(score_1);
//            balltime = 0;
//        }
//        
//        led1 = detector1; // toggle led based on value of the pin
        
        if (gc.goal) {
            score_1 = gc.get_score();
            balltime = gc.get_balltime();
            speed = gc.get_ballspeed();
            pc.printf("Score : %d \n\r", score_1);
            pc.printf("Time of ball pass : %f seconds\n\r", balltime);
            pc.printf("Speed of ball (34 mm diameter) : %f kph\n\r", speed);
            gc.goal = 0;
            }
    }
}