|
@@ -39,10 +39,9 @@ class Atm_blink : public Machine {
|
|
|
|
|
|
public:
|
|
|
Atm_blink( void ) : Machine() {};
|
|
|
-
|
|
|
short pin;
|
|
|
atm_timer_millis timer;
|
|
|
-
|
|
|
+ OSCMessage _msg ;
|
|
|
EthernetUDP* _udpRef ;
|
|
|
//Atm_blink& onOSC(OSCMessage& msg );
|
|
|
|
|
@@ -62,6 +61,7 @@ class Atm_blink : public Machine {
|
|
|
timer.set( blinkrate );
|
|
|
pinMode( pin, OUTPUT );
|
|
|
this->_udpRef = &udpRef;
|
|
|
+
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -69,9 +69,9 @@ class Atm_blink : public Machine {
|
|
|
switch ( id ) {
|
|
|
case EVT_TIMER :
|
|
|
return timer.expired( this );
|
|
|
- }
|
|
|
- return 0;
|
|
|
+
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
void action( int id ) {
|
|
|
|
|
@@ -79,119 +79,120 @@ class Atm_blink : public Machine {
|
|
|
case ENT_ON :
|
|
|
digitalWrite( pin, HIGH );
|
|
|
|
|
|
+
|
|
|
return;
|
|
|
|
|
|
case ENT_OFF :
|
|
|
digitalWrite( pin, LOW );
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ Atm_blink& trigger( int event ) {
|
|
|
+ Machine::trigger( event );
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Optionally override the default state() method
|
|
|
+ * Control what the machine returns when another process requests its state
|
|
|
+ */
|
|
|
+ // Atm_led& Atm_led::on( void ) {
|
|
|
+ // trigger( EVT_ON );
|
|
|
+ // return *this;
|
|
|
+
|
|
|
+
|
|
|
Atm_blink& onOSC(OSCMessage& msg ){
|
|
|
- if(msg.fullMatch("/truc")){
|
|
|
- OSCMessage _msg("/blink");
|
|
|
- _msg.add("youpi");
|
|
|
- _udpRef->beginPacket(ipMulti, portMulti);
|
|
|
- _msg.send(*_udpRef); // send the bytes to the SLIP stream
|
|
|
- _udpRef->endPacket(); // mark the end of the OSC Packet
|
|
|
- _msg.empty();
|
|
|
+ Serial.println("OSC");
|
|
|
+ if(msg.fullMatch("/blink")){
|
|
|
+ Serial.println("ouais gros");
|
|
|
+ // int blinkstate = _msg.getInt(0);
|
|
|
+ // blinkstate ? trigger(EVT_ON) : trigger(EVT_OFF);
|
|
|
+ _msg = new OSCMessage("/on");
|
|
|
+ _msg.add("youpi");
|
|
|
+ _udpRef->beginPacket(ipMulti, portMulti);
|
|
|
+ _msg.send(*_udpRef); // send the bytes to the SLIP stream
|
|
|
+ _udpRef->endPacket(); // mark the end of the OSC Packet
|
|
|
+ _msg.empty();
|
|
|
+ return *this;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
};
|
|
|
|
|
|
Atm_blink led;
|
|
|
|
|
|
void test(OSCMessage &msg, int addrOffset){
|
|
|
+ Serial.println("test");
|
|
|
msg.getInt(0)?led.trigger( led.EVT_ON ):led.trigger( led.EVT_OFF );
|
|
|
}
|
|
|
|
|
|
-void routeTone(OSCMessage &msg, int addrOffset ){
|
|
|
-//iterate through all the analog pins
|
|
|
-for(byte pin = 0; pin < NUM_DIGITAL_PINS; pin++){
|
|
|
- //match against the pin number strings
|
|
|
- int pinMatched = msg.match("5", addrOffset);
|
|
|
- if(pinMatched){
|
|
|
- unsigned int frequency = 0;
|
|
|
- //if it has an int, then it's an integers frequency in Hz
|
|
|
- if (msg.isInt(0)){
|
|
|
- frequency = msg.getInt(0);
|
|
|
- } //otherwise it's a floating point frequency in Hz
|
|
|
- else if(msg.isFloat(0)){
|
|
|
- frequency = msg.getFloat(0);
|
|
|
- }
|
|
|
- else
|
|
|
- noTone(pin);
|
|
|
- if(frequency>0)
|
|
|
- {
|
|
|
- if(msg.isInt(1))
|
|
|
- tone(pin, frequency, msg.getInt(1));
|
|
|
- else
|
|
|
- tone(pin, frequency);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-}
|
|
|
+
|
|
|
|
|
|
void setup() {
|
|
|
- SPI.setSCK(27);
|
|
|
- Ethernet.init(10);
|
|
|
+ //SPI.setSCK(27);
|
|
|
+ Ethernet.init(15);//(10)
|
|
|
teensyMAC(mac);
|
|
|
Ethernet.begin(mac, ip); // start the Ethernet and UDP:
|
|
|
// Udp.beginMulti(ipMulti, portMulti); // for modified Arduino library
|
|
|
Udp.beginMulticast(ipMulti, portMulti); // for modified Teensy Ethernet library
|
|
|
Serial.begin(115200); // higher Baud rate for faster refresh, CHANGE IN SERIAL MONITOR
|
|
|
|
|
|
- led.begin( 14, 200, Udp); // Setup a blink machine on pin 4
|
|
|
- led.trigger( led.EVT_ON ); // Turn it on
|
|
|
+ // led.begin( 14, 200, Udp); // Setup a blink machine on pin 4
|
|
|
+ // led.trigger( led.EVT_ON ); // Turn it on
|
|
|
|
|
|
- Serial.begin( 9600 );
|
|
|
- delay(1000);
|
|
|
- stepper.trace( Serial );
|
|
|
- Serial.println("Started");
|
|
|
- stepper.begin(A_stepper);
|
|
|
- stepper.cycle(1000);
|
|
|
- Serial.println("Started");
|
|
|
- stepper.gotoStep(1000);
|
|
|
- controller.moveAsync(*stepper.motor);
|
|
|
delay(1000);
|
|
|
- controller.moveAsync(*stepper.motor);
|
|
|
- delay(10000);
|
|
|
- stepper.motor->setMaxSpeed(30000);
|
|
|
- stepper.motor->setAcceleration(10000);
|
|
|
- stepper.gotoStep(-100000);
|
|
|
- controller.moveAsync(*stepper.motor);
|
|
|
- Serial.println("Started");
|
|
|
+
|
|
|
+ // stepper.trace( Serial );
|
|
|
+ // Serial.println("Started");
|
|
|
+ // stepper.begin(A_stepper);
|
|
|
+ // stepper.cycle(1000);
|
|
|
+ // Serial.println("Started");
|
|
|
+ // stepper.gotoStep(1000);
|
|
|
+ // controller.moveAsync(*stepper.motor);
|
|
|
+ // delay(1000);
|
|
|
+ // controller.moveAsync(*stepper.motor);
|
|
|
+ // delay(10000);
|
|
|
+ // stepper.motor->setMaxSpeed(30000);
|
|
|
+ // stepper.motor->setAcceleration(10000);
|
|
|
+ // stepper.gotoStep(-100000);
|
|
|
+ // controller.moveAsync(*stepper.motor);
|
|
|
+ // Serial.println("Started");
|
|
|
// stepper.trigger(stepper.EVT_GOTO);
|
|
|
// pinMode(00, OUTPUT);
|
|
|
// digitalWrite(0, HIGH);
|
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
- automaton.run();
|
|
|
- OSCMessage msgIn;
|
|
|
- int size;
|
|
|
-
|
|
|
- if( (size = Udp.parsePacket())>0)
|
|
|
- {
|
|
|
- while(size--)
|
|
|
- msgIn.fill(Udp.read());
|
|
|
-
|
|
|
- if(!msgIn.hasError())
|
|
|
- msgIn.route("/blink", test);
|
|
|
- led.onOSC(msgIn);
|
|
|
- }
|
|
|
-
|
|
|
- // OSCMessage msg("/analog/0");
|
|
|
- // msg.add((int32_t)analogRead(0));
|
|
|
+ // automaton.run();
|
|
|
+ // OSCMessage msgIn;
|
|
|
+ // int size;
|
|
|
+ Serial.println("msgIn");
|
|
|
+ // if( (size = Udp.parsePacket())>0)
|
|
|
+ // {
|
|
|
+ // while(size--)
|
|
|
+ // msgIn.fill(Udp.read());
|
|
|
+ //
|
|
|
+ // if(!msgIn.hasError()){
|
|
|
+ // // msgIn.route("/blink", test);
|
|
|
+ // // led.onOSC(msgIn);
|
|
|
+ // }
|
|
|
//
|
|
|
- // Udp.beginPacket(ipMulti, portMulti);
|
|
|
- // msg.send(Udp); // send the bytes to the SLIP stream
|
|
|
- // Udp.endPacket(); // mark the end of the OSC Packet
|
|
|
- // msg.empty(); // free space occupied by message
|
|
|
+ //
|
|
|
+ // }
|
|
|
+
|
|
|
+ OSCMessage msg("/analog/0");
|
|
|
+ msg.add((int32_t)analogRead(0));
|
|
|
+
|
|
|
+ Udp.beginPacket(ipMulti, portMulti);
|
|
|
+ msg.send(Udp); // send the bytes to the SLIP stream
|
|
|
+ Udp.endPacket(); // mark the end of the OSC Packet
|
|
|
+ msg.empty(); // free space occupied by message
|
|
|
|
|
|
// led.cycle();
|
|
|
|
|
|
- //delay(10);
|
|
|
+ delay(100);
|
|
|
//UDPsend(); // sending of packets; do not use with UDPreceive because it's including delay()!!
|
|
|
//UDPreceive();
|
|
|
|