first of all, im new to micro controllers, im building a firework controller that will fire via my iphone, ive picked out the app on the phone and im using iosc. ive tried to use a iphone iosc test sketch to control some leds and im pretty sure that its communicating because i open the serial monitor and the messages get sent and the rx light on the ethernet board lights up everytime i hit a button, if someone out there has a lil extra time it would be awesome if u could help me out with this. if there is someone that could help this is the code ive been trying
if it makes any difference im using arduino software version 21
if someone can message me and actually help out i wouldnt mind paying them a bit for the help!!
iOSC setting
OSCMessage type value on off
button1 /ard/ledyel int 1 0 :info-AlternateMode "ON" =toggle sw
button2 /ard/ledgrn int 1 0
button3 /ard/ledred int 1 0
slider1 /ard/ledpwm int min:0 max:255
host setting IP address 192.168.1.99 , port 10000
*/
#include "Ethernet.h"
#include "OSCClass.h"
#include "SPI.h"
#define LED_RED 2
#define LED_GRN 3
#define LED_YEL 4
#define LED_PWM 6
OSCMessage recMes;
OSCClass osc(&recMes);
byte serverMac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x3F, 0xF0 };
byte serverIp[] = { 192, 168, 2, 9 };
int serverPort = 10000;
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
char *topAddress="/ard";
char *subAddress[4]={ "/ledred" , "/ledgrn" , "/ledyel" , "/ledpwm"};
void setup() {
//for message logging
Serial.begin(19200);
// Ethernet.begin(serverMac ,serverIp);
Ethernet.begin(serverMac ,serverIp ,gateway ,subnet);
//setting osc recieve server
osc.begin(serverPort);
pinMode(LED_RED, OUTPUT);
pinMode(LED_GRN, OUTPUT);
pinMode(LED_YEL, OUTPUT);
pinMode(LED_PWM, OUTPUT);
digitalWrite(LED_RED, LOW); //LED OFF
digitalWrite(LED_GRN, LOW); //LED OFF
digitalWrite(LED_YEL, LOW); //LED OFF
digitalWrite(LED_PWM, LOW); //LED OFF
//osc message buffer clear
osc.flush();
}
void loop() {
//osc arrive check
if ( osc.available() ) {
logMessage(&recMes);
//toplevel address matching
if( !strcmp( recMes.getAddress(0) , topAddress ) ){
//second level address matching
if( !strcmp( recMes.getAddress(1) , subAddress[0] ) ){
red();
}
else if( !strcmp( recMes.getAddress(1) , subAddress[1] ) ){
green();
}
else if( !strcmp( recMes.getAddress(1) , subAddress[2] ) ){
yellow();
}
else if( !strcmp( recMes.getAddress(1) , subAddress[3] ) ){
pwm();
}
}
}
}
void red(){
if(recMes.getArgInt(0) == 1){
digitalWrite(LED_RED, HIGH); //LED_ON
}
else{
digitalWrite(LED_RED, LOW); //LED OFF
}
}
void green(){
if(recMes.getArgInt(0) == 1){
digitalWrite(LED_GRN, HIGH); //LED_ON
}
else{
digitalWrite(LED_GRN, LOW); //LED OFF
}
}
void yellow(){
if(recMes.getArgInt(0) == 1){
digitalWrite(LED_YEL, HIGH); //LED_ON
}
else{
digitalWrite(LED_YEL, LOW); //LED OFF
}
}
void pwm(){
byte value=(byte)recMes.getArgInt(0);
analogWrite(LED_PWM, 255-value);
}
// ********* utility ***********************************
void logMessage(OSCMessage *mes){
uint8_t *ip=mes->getIp();
//disp ip & port
Serial.print("from IP:");
Serial.print(ip[0],DEC);
Serial.print(".");
Serial.print(ip[1],DEC);
Serial.print(".");
Serial.print(ip[2],DEC);
Serial.print(".");
Serial.print(ip[3],DEC);
Serial.print(" port:");
Serial.print(mes->getPort(),DEC);
Serial.print(" ");
//disp adr
for(int i = 0 ; i < mes->getAddressNum() ; i++){
Serial.print(mes->getAddress(i));
}
//disp type tags
Serial.print(" ,");
for(int i = 0 ; i < mes->getArgNum() ; i++){
Serial.print(mes->getTypeTag(i));
}
Serial.print(" ");
//disp args
for(int i = 0 ; i < mes->getArgNum() ; i++){
switch( mes->getTypeTag(i) ){
case 'i': {
Serial.print( mes->getArgInt(i) );
}
break;
case 'f': {
Serial.print( mes->getArgFloat(i) );
}
break;
}
Serial.print(" ");
}
Serial.println("");
}