Lub-dub

 

1reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • WRTyler
    • -the National Mall guy-
    • wrTyler
    • 2 yrs ago
    • Reported - view

    Ooops, forgot to include the code for this effect.

    //Heartbeat LED for BrickPixel
    // elCalvoMike 12-6-2008
    // modified by Wayne R. Tyler 2021'11'09
    
    // library for controlling the BrickPixel hardware (REQUIRED)
    #include <Adafruit_NeoPixel.h>
    
     //analog pin location for ArduinoMini - change for other boards
    #define LED LED_BUILTIN
    
    // The BrickPixel equivalent of ledPin
    Adafruit_NeoPixel pixels(3, 7, NEO_RGB + NEO_KHZ800);
    
    int i = 0;
    int pmw = 255; //set PWM max - this can differ for other board pins
    int rate = 25; //this is the beats per minute (60000 ms)
    
    //because there are two beats to simulate the ‘lub-dub’ of the heart,
    // a 60 beat heart rate is only a value of 30 in the rate variable
    //the delay is the key to this programs realism - divide the rate into a minute, then weight it and divide by the pmw
    //you can modify the weight by changing the fractions (i.e .1, .2, .6) but to keep the timing correct, they should total 1
    //.1+.2+.1+.6 = 1
    
    void setup() {
        pinMode( LED, OUTPUT );
    
        // Initialize the NeoPixel object (this is REQUIRED)
        pixels.begin();
    
        // Clear out any prior BrickPixel settings
        pixels.clear();
    }
    
    // changed pixels.Color(i, i, i); to pixels.Color(i/5, i/5, i/5) so
    //   BrickPixel LEDs didn't blast you with light.
    void loop(){
        for( i = 0; i < pmw; i++ ) {
            analogWrite( LED, i );
            pixels.setPixelColor( 0, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 1, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 2, pixels.Color(i/5, i/5, i/5) );
            pixels.show();
            delay( ((60000/rate)*.1)/pmw );
        }
    
        for( i = pmw; i > 0; i-- ) {
            analogWrite( LED, i );
            pixels.setPixelColor( 0, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 1, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 2, pixels.Color(i/5, i/5, i/5) );
            pixels.show();
            delay( ((60000/rate)*.2)/pmw );
        }
    
        for( i = 0; i < pmw; i++ ) {
            analogWrite( LED, i );
            pixels.setPixelColor( 0, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 1, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 2, pixels.Color(i/5, i/5, i/5) );
            pixels.show();
            delay( ((60000/rate)*.1)/pmw );
        }
    
        for( i = pmw; i > 0; i-- ) {
            analogWrite( LED, i );
            pixels.setPixelColor( 0, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 1, pixels.Color(i/5, i/5, i/5) );
            pixels.setPixelColor( 2, pixels.Color(i/5, i/5, i/5) );
            pixels.show();
            delay( ((60000/rate)*.6)/pmw );
        }
    }
    Like
Like1 Follow
  • 1 Likes
  • 2 yrs agoLast active
  • 1Replies
  • 22Views
  • 1 Following