OneSheeld processing arduino sphere 3D

Arduino koden

#define CUSTOM_SETTINGS
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#include <OneSheeld.h>

const char rotate[]="rotate";
const char stopp[]="stop";
const char rotatefast[]="rotate fast";


void setup()
{
  OneSheeld.begin();
  Serial.begin(115200); 
}

void loop()
{
   
   if(VoiceRecognition.isNewCommandReceived())
    {
      if(!strcmp(rotate,VoiceRecognition.getLastCommand()))
            {
           // TextToSpeech.say("yes");
             Serial.write(1);
            }
      else if(!strcmp(stopp,VoiceRecognition.getLastCommand()))
            {
           // TextToSpeech.say("yes");
            Serial.write(2); 
            }
      else if(!strcmp(rotatefast,VoiceRecognition.getLastCommand()))
            {
           // TextToSpeech.say("yes");
            Serial.write(3); 
            }
     }
}
   

Processing koden

import processing.serial.*;          // inkludera serial biblioteket 
Serial myPort;                       // Skapa ett serial objekt

float x;
float rotX;

void setup()
  {
    size(800,600,P3D);  // fönsterstorleken samt vilken rendering
    x = 0;
    rotX = 0;
      

  // Print a list of the serial ports for debugging purposes
  // if using Processing 2.1 or later, use Serial.printArray()
  println(Serial.list());
  String portName = Serial.list()[2];
  myPort = new Serial(this, portName, 115200);
  }

void draw()
  {
    background(#585757);         // bakgrundsfärg
    pushMatrix();                // starta "transformationen" 
    translate(400, 300, 0);      // flytta koordinatsystemet
    rotateX(rotX);               // rotera kring y-axeln
    rotateY(rotX);               // rotera kring y-axeln
    noFill();                    // fyll inte med färg
    strokeWeight(1.5);           // tjocklek
    stroke(255);
    sphere(170);                 // klot(diameter i px)
    popMatrix();                 // avsluta "transformationen"
    rotX = rotX + x;             // öka rotationen hela tiden med x
  }
  
  
void serialEvent(Serial myPort) {  // funktionen för serialhändelser

  int a = myPort.read();           // läs porten och spara byten i variabeln inByte
  println(a);
  if (a == 1)
    {
      x = 0.01;
    }
  else if(a==2)
    {
      x = 0;
    }
  else if(a==3)
    {
      x = 0.03;
    }
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s