Lex DreitserJavair RatliffAlbert SchweitzerShiv DallaNeil Shah
Published © GPL3+

No Sleep til Demo

It's CRUNCHTIME! An app for those times when you absolutely have to stay awake and finish something important.

ExpertWork in progress603
No Sleep til Demo

Code

Bean Code

C#
We ended up using Light Blue Bean because it was so freikin cool.
/* 
  NO SLEEP TIL DEMO
  Detects the absence of movent (user fell asleep) 
then blinks and sends vibration signal to  
*/

// When acceleration change goes beyond this threshold, the  blink.
#define THRESHOLD 50

AccelerationReading previousAccel;

void setup() {
  // Turn off the Bean's LED
  Bean.setLed(0, 0, 0);  
  // Initial reading  
  previousAccel = Bean.getAcceleration(); 
}

// This function calculates the difference between two acceleration readings
int getAccelDifference(AccelerationReading readingOne, AccelerationReading readingTwo){
  int deltaX = abs(readingTwo.xAxis - readingOne.xAxis);
  int deltaY = abs(readingTwo.yAxis - readingOne.yAxis);
  int deltaZ = abs(readingTwo.zAxis - readingOne.zAxis);
  // Return the magnitude
  return deltaX + deltaY + deltaZ;   
}

void loop() {
  // Get the current acceleration with a conversion of 3.9110-3 g/unit.
  AccelerationReading currentAccel = Bean.getAcceleration();   
  
  // Find the difference between the current acceleration and that of 200ms ago.
  int accelDifference = getAccelDifference(previousAccel, currentAccel); 
  // Update previousAccel for the next loop.   
  previousAccel = currentAccel;                                            
  
  // Check if the Bean has been moved beyond our threshold.
  if(accelDifference > THRESHOLD){   
    // Blink the LED
    Bean.sleep(1900);
  }
    else{
    
        Bean.setLed(255,0,0);
        Bean.sleep(10);
        Bean.setLed(0,255,0);
        Bean.sleep(10);
        Bean.setLed(0,0,255);
        Bean.sleep(10);
        Bean.setLed(255,100,100);
        Bean.sleep(10);
        Bean.setLed(0,0,0);
        Bean.sleep(10);
  }
}

Credits

Lex Dreitser

Lex Dreitser

13 projects • 39 followers
Tech Lead - IA - LAMP Expert w/ SEM SEO UX UI Ecom content focus. API guru. IoT Modern Roboticist. Friend.
Javair Ratliff

Javair Ratliff

4 projects • 2 followers
Albert Schweitzer

Albert Schweitzer

6 projects • 6 followers
Shiv Dalla

Shiv Dalla

4 projects • 1 follower
University of Pennsylvania '18 | Bioengineering University of Pennsylvania '19 | Robotics University of Kansas School of Medicine '23 | MD
Neil Shah

Neil Shah

2 projects • 0 followers

Comments