Skip to content

Commit

Permalink
Pong project
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBleijendaal committed Sep 30, 2016
1 parent 2b6ec9d commit c52ffab
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 0 deletions.
1 change: 1 addition & 0 deletions Arduino/Edt_2000_OSC_Test3Pong/.gitignore
@@ -0,0 +1 @@
.pioenvs
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>
38 changes: 38 additions & 0 deletions Arduino/Edt_2000_OSC_Test3Pong/lib/readme.txt
@@ -0,0 +1,38 @@

This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.

The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".

For example, see how can be organized `Foo` and `Bar` libraries:

|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c

Then in `src/main.c` you should use:

#include <Foo.h>
#include <Bar.h>

// rest H/C/CPP code

PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.

See additional options for PlatformIO Library Dependency Finder `lib_*`:

http://docs.platformio.org/en/latest/projectconf.html#lib-install

8 changes: 8 additions & 0 deletions Arduino/Edt_2000_OSC_Test3Pong/platformio.ini
@@ -0,0 +1,8 @@
[env:uno]
platform = atmelavr
framework = arduino
board = leonardoeth
upload_port = COM8

[platformio]
lib_dir = D:\Edt-2000\Arduino\libraries
145 changes: 145 additions & 0 deletions Arduino/Edt_2000_OSC_Test3Pong/src/main.cpp
@@ -0,0 +1,145 @@
/*
Edt-2000 Test Ping
*/
#define DEBUG

#define STARTIO 5
#define FINISHIO 6

#define SYS 0
#define STEP 1
#define FULL 2

#include "Definitions.h"

#include "Arduino.h"
#include "Ethernet.h"
#include "EthernetUdp.h"
#include "OSC.h"
#include "Statemachine.h"
#include "Preset.h"
#include "Trak.h"
#include "Time.h"
#include "Memory.h"

EthernetUDP Udp;
EdtOSC OSC;

enum class states { init, waitingForStart, waitingForFinish, waitingForReset };
states state = states::init;

class OSCMessageWriter : public EdtOSCSourceObject
{
public:
OSCMessageWriter() {
message.reserve(1);
message.setAddress("/M");
}
OSCMessage * generateMessage() {
if (enabled) {

message.add(++messages);

enabled = false;

return &message;
}

return nullptr;
}
void enable() {
enabled = true;
}
private:
OSCMessage message = OSCMessage();
float messages = 0;
bool enabled = false;
} OSCWriter;

void setup() {
Statemachine.begin(13, LOW);

pinMode(STARTIO, INPUT_PULLUP);
pinMode(FINISHIO, INPUT_PULLUP);
}

void loop() {
Statemachine.loop();

if (Statemachine.isBegin()) {
Time.begin();

Time.startTiming(SYS);
Time.startTiming(STEP);
Time.startTiming(FULL);

Serial.begin(9600);

// Pong code
Time.addTimeEvent(SYS, "Edt-Trak Ping");

Time.addTimeEvent(SYS, "Starting Ethernet..");

Ethernet.begin(MAC_PONG);

Time.addTimeEvent(SYS, "Started Ethernet.");

Serial.print("IP: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();

Time.addTimeEvent(SYS, "Starting UDP..");

Udp.begin(PORT_BROADCAST);

Time.addTimeEvent(SYS, "Started UDP.");
Time.addTimeEvent(SYS, "Starting code..");

OSC = EdtOSC(1, 0);
OSC.bindUDP(&Udp, IP_BROADCAST, PORT_BROADCAST);
OSC.addSource(&OSCWriter);

Time.addTimeEvent(SYS, "Started code.");
// /Pong code

Statemachine.ready();
}
else {
while (Statemachine.isRun()) {
Time.loop();
OSC.loop();

switch (state) {
case states::init:
Time.addTimeEvent(FULL, "Start cycle.");
state = states::waitingForStart;
break;

case states::waitingForStart:
if (digitalRead(STARTIO) == HIGH) {
Time.addTimeEvent(FULL, "Received start.");
state = states::waitingForFinish;
OSCWriter.enable();
}
break;

case states::waitingForFinish:
if (digitalRead(FINISHIO) == HIGH) {
Time.addTimeEvent(FULL, "Received finish.");
state = states::waitingForReset;
}
break;

case states::waitingForReset:
if (digitalRead(STARTIO) == LOW && digitalRead(FINISHIO) == LOW) {
Time.addTimeEvent(FULL, "Received reset.");
state = states::init;
}
break;
}
}
}
}

0 comments on commit c52ffab

Please sign in to comment.