Deaf Assistance Device Code

Used For Research Purposes.
 avatar
unknown
c_cpp
a year ago
1.3 kB
11
Indexable
//VARIABLE DECLARATION
float lastmil = 0; // Unmodifiable | Used For DecrementTimer Method | Value: 0
const float timerconstant = 0.7f; // Modifiable | How Long A Vibration Is Sustained | Values: [0, +Infinity]
float currenttimer = timerconstant; // Unmodifiable | Used For Sustaining Vibrations | Value: timerconstant
const int sensitivity = 100; // Modifiable | When To Trigger Vibration | Values: [0, 225]
int highestvibration = 0; // Unmodifiable | Highest Vibration Received Since currenttimer Variable Began | Value: Highest Vibration Received
int minstrength = 0; // Modifiable | Lowest Vibration Strength After Passing Sensitivity Threshold | Values: [0, 255]
void setup(){}
void loop() //LOOPING METHOD
{
   int SoundStrength = map(analogRead(A1), 0, 1023, minstrength, 255); //Converts Sound Input To Vibration Strength
  if(SoundStrength > highestvibration)
  {
    analogWrite(3,SoundStrength);
    currenttimer = 0.7f; 
  }
  else
  {
    if(millis() - lastmil >= 10)
    {
     DecrementTimer(); 
    }
  }
}
void DecrementTimer() //DECREMENT TIMER FOR SUSTAINING VIBRATIONS
{
  lastmil = millis();
    currenttimer -= 0.01f;
  if (currenttimer <= 0)
  {
    analogWrite(3, 0);
    highestvibration = sensitivity;
  }
}
Editor is loading...
Leave a Comment