Ejemplo n.º 1
0
float Read_PT(int PT)
{
  // make 16 readings and average them (reduces some noise) you can tune the number 16 of course
  float val;
  int count = 16, raw = 0, sensorValue = 0;
  for(int i = 0; i< count; i++)
  {
    if(PT) 
    {
      sensorValue = analogRead(Pressure);
      raw += sensorValue;
    }
    else 
    {
      sensorValue = analogRead(Temp);
      raw += sensorValue;
    }
  }
  raw = raw / count; // return 0..1023 representing 0..5V
  float voltage = 5.0 * raw / 1023; //CONVERT TO VOLTAGE voltage = 0..5V;  we do the math in millivolts!!
//  Serial.print(voltage);
//  Serial.println();
  if(PT)  val = mapFloat(voltage, 0.88, 4.4, 0, 50);  // Pressure
  else  val = mapFloat(voltage, 0.88, 4.4, 32, 135);  // Temperature
  return val;
}
Ejemplo n.º 2
0
void Ramp::update() {
	// Offset elapsed time.
	_elapsedTime = _offsetTime;

	if (_isRunning) {
		// Add difference to elapsed time.
	 	_elapsedTime += (seconds() - _startTime);

		// Compute value if running -- otherwise leave as is.
		// TODO: implement easing functions
	  _value = mapFloat(progress(), 0.0f, 1.0f, _from, (_from + _change));
	}
}
Ejemplo n.º 3
0
 void main() {
     vec2 gravity = vec2(0.0, -0.0005);
     float max = 0.05;
     float maxSquared = max * max;
     
     outPos = inPos;
     outVel = inVel;
     outVel += gravity;
     
     // limit speed
     float speedSquared = dot(outVel, outVel);
     if (speedSquared > maxSquared) {
         vec2 norm = normalize(outVel);
         outVel *= max;
     }
     
     outPos += outVel;
     
     // keep in frame
     if (inPos.y < -1.0) {
         outPos.x = 0.0;
         outPos.y = 0.0;
         
         // reset velocity and position
         
         // use position to generate random number for velocity direction
         float newFloat = getRandomFloat(inPos);
         
         // use a different vector to generate a random number for velocity length
         vec2 altVec;
         if (inPos.x != 0.0 && inPos.y != 0.0) {
             altVec = inPos + vec2(1.0/inPos.x, 1.0/inPos.y);
         } else {
             altVec = inPos;
         }
         
         float newSpeed = getRandomFloat(altVec);
         newSpeed = mapFloat(newSpeed, 0.0, 1.0, 0.06, 0.15); // make min output number smaller; why does that happen?
         
         outVel = getDir(newFloat);
         outVel *= newSpeed;
         outPos = mousePos;
     }
     
     outCol = inCol;
     gl_Position = vec4(outPos, 0.0, 1.0);
 }
Ejemplo n.º 4
0
/*
 * encoderRead() function is used to read the encoder value in degrees
 */
float encoderRead()
{
  return mapFloat(myEnc.read(), 0, 5260, 0, 360);
}