-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
403 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
/* | ||
* Arduino wiring: | ||
* | ||
* Digital pin Connected to | ||
* ----------- ------------ | ||
* 2 Sensor 0 | ||
* 3 Sensor 1 | ||
* 4 Sensor 2 | ||
* 5 Sensor 3 | ||
* | ||
* 9 Racer0 Start LED anode, Stop LED cathode | ||
* 10 Racer1 Start LED anode, Stop LED cathode | ||
* 11 Racer2 Start LED anode, Stop LED cathode | ||
* 12 Racer3 Start LED anode, Stop LED cathode | ||
* | ||
*/ | ||
|
||
#define VERSION "basic-1.03" | ||
#define FALSE_START_TICKS 4 | ||
|
||
int statusLEDPin = 13; | ||
long statusBlinkInterval = 250; | ||
int lastStatusLEDValue = LOW; | ||
long previousStatusBlinkMillis = 0; | ||
|
||
boolean raceStarted = false; | ||
boolean raceStarting = false; | ||
boolean mockMode = false; | ||
unsigned long raceStartMillis; | ||
unsigned long currentTimeMillis; | ||
|
||
char val = 0; | ||
|
||
int racer0GoLedPin = 9; | ||
int racer1GoLedPin = 10; | ||
int racer2GoLedPin = 11; | ||
int racer3GoLedPin = 12; | ||
|
||
int sensorPins[4] = {2,3,4,5}; | ||
int previoussensorValues[4] = {HIGH,HIGH,HIGH,HIGH}; | ||
int values[4] = {0,0,0,0}; | ||
unsigned long racerTicks[4] = {0,0,0,0}; | ||
unsigned long racerFinishTimeMillis[4]; | ||
|
||
unsigned long lastCountDownMillis; | ||
int lastCountDown; | ||
|
||
char charBuff[8]; | ||
unsigned int charBuffLen = 0; | ||
boolean isReceivingRaceLength = false; | ||
|
||
int raceLengthTicks = 20; | ||
int previousFakeTickMillis = 0; | ||
|
||
int updateInterval = 50; | ||
unsigned long lastUpdateMillis = 0; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
pinMode(statusLEDPin, OUTPUT); | ||
pinMode(racer0GoLedPin, OUTPUT); | ||
pinMode(racer1GoLedPin, OUTPUT); | ||
pinMode(racer2GoLedPin, OUTPUT); | ||
pinMode(racer3GoLedPin, OUTPUT); | ||
digitalWrite(racer0GoLedPin, LOW); | ||
digitalWrite(racer1GoLedPin, LOW); | ||
digitalWrite(racer2GoLedPin, LOW); | ||
digitalWrite(racer3GoLedPin, LOW); | ||
for(int i=0; i<=3; i++) | ||
{ | ||
pinMode(sensorPins[i], INPUT); | ||
digitalWrite(sensorPins[i], HIGH); | ||
} | ||
|
||
} | ||
|
||
void blinkLED() { | ||
if (millis() - previousStatusBlinkMillis > statusBlinkInterval) { | ||
previousStatusBlinkMillis = millis(); | ||
lastStatusLEDValue = !lastStatusLEDValue; | ||
digitalWrite(statusLEDPin, lastStatusLEDValue); | ||
} | ||
|
||
} | ||
|
||
void raceStart() { | ||
raceStartMillis = millis(); | ||
} | ||
|
||
boolean isAlphaNum(char c) { | ||
if(c >= '0' && c <= '9'){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void checkSerial(){ | ||
if(Serial.available() > 0) { | ||
val = Serial.read(); | ||
if(val == '\r' || val == '\n') { | ||
if(isReceivingRaceLength){ | ||
isReceivingRaceLength = false; | ||
raceLengthTicks = atoi(charBuff); | ||
Serial.print("L:"); | ||
Serial.println(raceLengthTicks); // send confirmation | ||
} | ||
|
||
// Ignore end-of-line characters. | ||
return; | ||
} | ||
if(isReceivingRaceLength) { | ||
charBuff[charBuffLen] = val; | ||
charBuffLen++; | ||
} | ||
else { | ||
if(val == 'l') { | ||
charBuffLen = 0; | ||
isReceivingRaceLength = true; | ||
} | ||
else if(val == 'v') { | ||
Serial.println(VERSION); | ||
} | ||
else if(val == 'g') { // start race | ||
for(int i=0; i<=3; i++) | ||
{ | ||
racerTicks[i] = 0; | ||
racerFinishTimeMillis[i] = 0; | ||
} | ||
|
||
raceStarting = true; | ||
raceStarted = false; | ||
lastCountDown = 4; | ||
lastCountDownMillis = millis(); | ||
} | ||
else if(val == 'm') { // toggle mock mode | ||
mockMode = !mockMode; | ||
if(mockMode){ Serial.println("M:ON"); } | ||
else{ Serial.println("M:OFF"); } | ||
} | ||
else if(val == 's') { // stop race | ||
raceStarted = false; | ||
raceStarting = false; | ||
|
||
digitalWrite(racer0GoLedPin,LOW); | ||
digitalWrite(racer1GoLedPin,LOW); | ||
digitalWrite(racer2GoLedPin,LOW); | ||
digitalWrite(racer3GoLedPin,LOW); | ||
} | ||
else { | ||
Serial.print("ERROR:Command invalid "); | ||
if(val > 32 && val < 127) { | ||
Serial.println(char(val)); | ||
} | ||
else { | ||
Serial.print("ERROR:Unprintable ASCII code "); | ||
Serial.println(val); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void printStatusUpdate() { | ||
if(currentTimeMillis - lastUpdateMillis > updateInterval) { | ||
lastUpdateMillis = currentTimeMillis; | ||
|
||
Serial.print("R:"); | ||
|
||
for(int i=0; i<=3; i++) | ||
{ | ||
Serial.print(racerTicks[i], DEC); | ||
Serial.print(","); | ||
} | ||
Serial.println(currentTimeMillis, DEC); | ||
} | ||
} | ||
|
||
void loop() { | ||
blinkLED(); | ||
|
||
checkSerial(); | ||
|
||
if (raceStarting) { | ||
// Report false starts | ||
for(int i=0; i<=3; i++) { | ||
values[i] = digitalRead(sensorPins[i]); | ||
if(racerTicks[i] < FALSE_START_TICKS) { | ||
if(values[i] == HIGH && previoussensorValues[i] == LOW){ | ||
racerTicks[i]++; | ||
if(racerTicks[i] == FALSE_START_TICKS) { | ||
Serial.print("FS:"); | ||
Serial.println(i, DEC); | ||
digitalWrite(racer0GoLedPin+i,LOW); | ||
} | ||
} | ||
} | ||
previoussensorValues[i] = values[i]; | ||
} | ||
|
||
if((millis() - lastCountDownMillis) > 1000){ | ||
lastCountDown -= 1; | ||
lastCountDownMillis = millis(); | ||
Serial.print("CD:"); | ||
Serial.println(lastCountDown, DEC); | ||
} | ||
if(lastCountDown == 0) { | ||
raceStart(); | ||
raceStarting = false; | ||
raceStarted = true; | ||
|
||
for(int i=0; i<=3; i++) { | ||
racerTicks[i] = 0; | ||
racerFinishTimeMillis[i] = 0; | ||
} | ||
|
||
digitalWrite(racer0GoLedPin,HIGH); | ||
digitalWrite(racer1GoLedPin,HIGH); | ||
digitalWrite(racer2GoLedPin,HIGH); | ||
digitalWrite(racer3GoLedPin,HIGH); | ||
} | ||
} | ||
if (raceStarted) { | ||
currentTimeMillis = millis() - raceStartMillis; | ||
|
||
for(int i=0; i<=3; i++) | ||
{ | ||
if(!mockMode) { | ||
values[i] = digitalRead(sensorPins[i]); | ||
if(values[i] == HIGH && previoussensorValues[i] == LOW){ | ||
racerTicks[i]++; | ||
if(racerFinishTimeMillis[i] == 0 && racerTicks[i] >= raceLengthTicks) { | ||
racerFinishTimeMillis[i] = currentTimeMillis; | ||
Serial.print(i); | ||
Serial.print("F:"); | ||
Serial.println(racerFinishTimeMillis[i], DEC); | ||
digitalWrite(racer0GoLedPin+i,LOW); | ||
} | ||
} | ||
previoussensorValues[i] = values[i]; | ||
} | ||
|
||
// MOCK MODE | ||
else { | ||
if(currentTimeMillis - lastUpdateMillis > updateInterval) { | ||
racerTicks[i] += (i+1); | ||
|
||
if(racerFinishTimeMillis[i] == 0 && racerTicks[i] >= raceLengthTicks) { | ||
racerFinishTimeMillis[i] = currentTimeMillis; | ||
Serial.print(i); | ||
Serial.print("F:"); | ||
Serial.println(racerFinishTimeMillis[i], DEC); | ||
digitalWrite(racer0GoLedPin+i,LOW); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
printStatusUpdate(); | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
------------------------------- | ||
UBUNTU FONT LICENCE Version 1.0 | ||
------------------------------- | ||
|
||
PREAMBLE | ||
This licence allows the licensed fonts to be used, studied, modified and | ||
redistributed freely. The fonts, including any derivative works, can be | ||
bundled, embedded, and redistributed provided the terms of this licence | ||
are met. The fonts and derivatives, however, cannot be released under | ||
any other licence. The requirement for fonts to remain under this | ||
licence does not require any document created using the fonts or their | ||
derivatives to be published under this licence, as long as the primary | ||
purpose of the document is not to be a vehicle for the distribution of | ||
the fonts. | ||
|
||
DEFINITIONS | ||
"Font Software" refers to the set of files released by the Copyright | ||
Holder(s) under this licence and clearly marked as such. This may | ||
include source files, build scripts and documentation. | ||
|
||
"Original Version" refers to the collection of Font Software components | ||
as received under this licence. | ||
|
||
"Modified Version" refers to any derivative made by adding to, deleting, | ||
or substituting -- in part or in whole -- any of the components of the | ||
Original Version, by changing formats or by porting the Font Software to | ||
a new environment. | ||
|
||
"Copyright Holder(s)" refers to all individuals and companies who have a | ||
copyright ownership of the Font Software. | ||
|
||
"Substantially Changed" refers to Modified Versions which can be easily | ||
identified as dissimilar to the Font Software by users of the Font | ||
Software comparing the Original Version with the Modified Version. | ||
|
||
To "Propagate" a work means to do anything with it that, without | ||
permission, would make you directly or secondarily liable for | ||
infringement under applicable copyright law, except executing it on a | ||
computer or modifying a private copy. Propagation includes copying, | ||
distribution (with or without modification and with or without charging | ||
a redistribution fee), making available to the public, and in some | ||
countries other activities as well. | ||
|
||
PERMISSION & CONDITIONS | ||
This licence does not grant any rights under trademark law and all such | ||
rights are reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of the Font Software, to propagate the Font Software, subject to | ||
the below conditions: | ||
|
||
1) Each copy of the Font Software must contain the above copyright | ||
notice and this licence. These can be included either as stand-alone | ||
text files, human-readable headers or in the appropriate machine- | ||
readable metadata fields within text or binary files as long as those | ||
fields can be easily viewed by the user. | ||
|
||
2) The font name complies with the following: | ||
(a) The Original Version must retain its name, unmodified. | ||
(b) Modified Versions which are Substantially Changed must be renamed to | ||
avoid use of the name of the Original Version or similar names entirely. | ||
(c) Modified Versions which are not Substantially Changed must be | ||
renamed to both (i) retain the name of the Original Version and (ii) add | ||
additional naming elements to distinguish the Modified Version from the | ||
Original Version. The name of such Modified Versions must be the name of | ||
the Original Version, with "derivative X" where X represents the name of | ||
the new work, appended to that name. | ||
|
||
3) The name(s) of the Copyright Holder(s) and any contributor to the | ||
Font Software shall not be used to promote, endorse or advertise any | ||
Modified Version, except (i) as required by this licence, (ii) to | ||
acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with | ||
their explicit written permission. | ||
|
||
4) The Font Software, modified or unmodified, in part or in whole, must | ||
be distributed entirely under this licence, and must not be distributed | ||
under any other licence. The requirement for fonts to remain under this | ||
licence does not affect any document created using the Font Software, | ||
except any version of the Font Software extracted from a document | ||
created using the Font Software may only be distributed under this | ||
licence. | ||
|
||
TERMINATION | ||
This licence becomes null and void if any of the above conditions are | ||
not met. | ||
|
||
DISCLAIMER | ||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF | ||
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER | ||
DEALINGS IN THE FONT SOFTWARE. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#version 150 | ||
|
||
in vec2 TexCoord0; | ||
|
||
out vec4 oColor; | ||
|
||
uniform vec4 baseColor; | ||
uniform float leadingEdgePct; | ||
uniform float trailingEdgePct; | ||
|
||
float map( float value, float inputMin, float inputMax, float outputMin, float outputMax ){ | ||
float outVal = ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); | ||
|
||
return max(outVal, outputMin); | ||
} | ||
|
||
void main() | ||
{ | ||
vec4 finalColor = baseColor; | ||
float colPct = map( TexCoord0.s, trailingEdgePct, leadingEdgePct, 0.0, 1.0 ); | ||
colPct = pow(colPct, 0.5); | ||
if( colPct > 1.0 || leadingEdgePct == 0.0 ){ | ||
discard; | ||
} | ||
|
||
finalColor.a = colPct; | ||
oColor = finalColor; | ||
} |
Oops, something went wrong.