Back to Parent

// CODE ITERATION 1: Using RGB
// Himanshu Rasam, Jon Sharrah, Ian Lee
Servo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position
int stock_analysis=0;
/*
int redPin = D2;    // RED pin of the LED to PWM pin **A0**
int greenPin = D0;  // GREEN pin of the LED to PWM pin **D0**
int bluePin = D1;   // BLUE pin of the LED to PWM pin **D1**
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255*/

void setup()
{
  myservo.attach(D3);  // attaches the servo on pin 0 to the servo object
  Particle.function ("newData", newData);
  Particle.variable ("stock_analysis", &stock_analysis, INT);
  indicator();
  // Set up our pins for output
  pinMode( redPin, OUTPUT);
  pinMode( greenPin, OUTPUT);
  pinMode( bluePin, OUTPUT);
  //Register our Particle Core function here
  Particle.function("led", ledControl);
  // turn them all off...
  analogWrite( redPin, redValue);
  analogWrite( greenPin, greenValue);
  analogWrite( bluePin, blueValue);
}



void loop()
{}
/*{
  if (stock_analysis<=3)
  { pos= (int)(stock_analysis/3*60);
    myservo.write (pos);
  }
  else if (stock_analysis>3 && stock_analysis<=6 )
  { pos= (int)(stock_analysis/3*60);
    myservo.write (pos);
  }
  else if (stock_analysis>6 && stock_analysis<=9 )
  { pos= (int)(stock_analysis/3*60);
    myservo.write (pos);
  }
}*/

/*int newData( String s_a)
{
  Serial.print( "Received = ");
  Serial.println( s_a );

  // if the first row is an decimal number and we wanted to extract
  // it from the string.. we would do this.
  // find the index of the first comma in the string
  int spacePos = s_a.indexOf(",");
  // create a substring from the first character to the first comma
  // and convert that to a floating point (decimal number).
  float spend = s_a.substring(0, spacePos ).toFloat();
  stock_analysis = spend;
  // Return 1 to say completed successfull
  return 1;

}*/
void indicator()
{
  if (stock_analysis<=3)
  { pos= (int)(stock_analysis/3*60);
    myservo.write (pos);
  }
  else if (stock_analysis>3 && stock_analysis<=6 )
  { pos= (int)(stock_analysis/3*60);
    myservo.write (pos);
  }
  else if (stock_analysis>6 && stock_analysis<=9 )
  { pos= (int)(stock_analysis/3*60);
    myservo.write (pos);
  }
  delay (3000);
}
}

/*int ledControl(String command)
{
    String colors[3];
    colors[0]="";
    colors[1]="";
    colors[2]="";
    int index = 0;
    for( int i = 0; i < command.length(); i++ )
    {
      if( index < 3 ){
        char c = command.charAt(i);
        colors[index] += c;
        if( c == ',') index++;
      }
    }
    // get the red component...
    redValue = colors[0].toInt();
    // now green
    greenValue = colors[1].toInt();
    // now blue
    blueValue = colors[2].toInt();
   // write the mixed color
   analogWrite( redPin, redValue);
   analogWrite( greenPin, greenValue);
   analogWrite( bluePin, blueValue);
   return 1;
}*/
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0