Go Down

Topic: Wert von TouchOSC auslesen und mit PWM subtrahieren (Read 558 times) previous topic - next topic

Jolle

Hallo,
ich möchte gern einen Wert, den ich per TouchOSC sende, mit dem Wert von der PWM subtrahieren.
hier mal ein Beispiel:

String Helligkeit = "/2/fader1";

if(Push1==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255);
           analogWrite(5, 0);
           analogWrite(3, 0);

Wenn ich mein Push1-Button drücke, ändert sich der Wert von Pin 6 von 0 auf 255. Um den Wert 255 abhängig von dem Wert des --->String Helligkeit = "/2/fader1"; <---- zu machen, fehlen mir ein paar Kenntnisse.


Ich hatte mir das so gedacht:

if(Push1==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255 - (255/100) * (der Wert von --->String Helligkeit = "/2/fader1"<---);
           analogWrite(5, 0);
           analogWrite(3, 0);

Wie bekomme ich den Wert von --->String Helligkeit = "/2/fader1"; <---- deklariert, damit ich ihn über z.b. x oder y in meine Funktion hinein bekomme?
also dann so: analogWrite(6, 255 - (255/100) * x);



Freue mich über eure Antworten/Erfahrungen/Meinungen.


Code: [Select]
#include <SPI.h>
#include <Ethernet.h> // version IDE 0022
#include <Z_OSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xFE, 0xFE, 0xED };
byte myIp[]  = { 192, 168, 178, 4 };
int  serverPort  = 8000;
byte gateway[] = { 192, 168, 178, 1 };    // ROUTER
byte subnet[] = {255, 255, 255, 0 };    // SUBNET
 

uint16_t i;
float floatValue;
Z_OSCServer server;
Z_OSCMessage *rcvMes;

void setup(){
//Serial.begin(19200);
Ethernet.begin(myMac ,myIp);
server.sockOpen(serverPort);
//Serial.println("init");

pinMode(7, OUTPUT);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
analogWrite(3,254);
  analogWrite(5,254);
   analogWrite(6,254);

}
 
void loop(){
if(server.available()){
   Serial.println("empfang");
   rcvMes=server.getMessage();
   
   for(i=0 ; i<rcvMes->getArgsNum(); i++){
     switch( rcvMes->getTypeTag(i) ){
       case 'f':       
         floatValue = rcvMes->getFloat(i);
         
          String Push1 = "/2/push14";
          String Push2 = "/2/push22";
          String Push3 = "/2/push19";
          String Push4 = "/2/push17";
          String Push5 = "/2/push16";
          String Push6 = "/2/push24";
          String Push7 = "/2/push13";
          String Push8 = "/2/push18";
          String Push9 = "/2/push23";
          String Push10 = "/2/push15";
          String Push11 = "/2/push20";
          String Push12 = "/2/push21";
          String Helligkeit = "/2/fader1";
          String reset = "/LED/push26";
          String reset2 = "/2/push27";
          String OK = "/2/push12";   
          String LEDON = "/3/push1";
          String LEDOFF = "/3/push2";
          String blue = "/LED/fader3";
          String red = "/LED/fader1";
          String green = "/LED/fader2";
         if(blue==rcvMes->getZ_OSCAddress()){
           analogWrite(3,floatValue);
         }
          if(red==rcvMes->getZ_OSCAddress()){
           analogWrite(6,floatValue);
         }
         if(green==rcvMes->getZ_OSCAddress()){
          analogWrite(5,floatValue);
        }
          if(LEDON==rcvMes->getZ_OSCAddress()){
          // ON
          digitalWrite(7,HIGH);
         }
          if(LEDOFF==rcvMes->getZ_OSCAddress()){
          // OFF
          digitalWrite(7,LOW);
          }
          if(Push1==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255);
           analogWrite(5, 0);
           analogWrite(3, 0);
           }
          if(Push2==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255);
           analogWrite(5, 96);
           analogWrite(3, 0);
           }
          if(Push3==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255);
           analogWrite(5, 255);
           analogWrite(3, 0);
           }
          if(Push4==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 96);
           analogWrite(5, 255);
           analogWrite(3, 0);
           }
          if(Push5==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 255);
           analogWrite(3, 0);
           }
           if(Push6==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 255);
           analogWrite(3, 96);
           }
           if(Push7==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 255);
           analogWrite(3, 255);
           }
           if(Push8==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 96);
           analogWrite(3, 255);
           }
           if(Push9==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 0);
           analogWrite(3, 255);
           }
           if(Push10==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 96);
           analogWrite(5, 0);
           analogWrite(3, 255);
           }
           if(Push11==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255);
           analogWrite(5, 0);
           analogWrite(3, 255);
           }
           if(Push12==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 255);
           analogWrite(5, 0);
           analogWrite(3, 96);
           }
           
        if(reset==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 0);
           analogWrite(3, 0);
           analogWrite(7, 0);
           }
           if(reset2==rcvMes->getZ_OSCAddress()){
           analogWrite(6, 0);
           analogWrite(5, 0);
           analogWrite(3, 0);
           analogWrite(7, 0);
           }
         
}
       break;
     }
   }
   
}   
 


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy