<li id="8g3ty"><tbody id="8g3ty"><th id="8g3ty"></th></tbody></li>
    <label id="8g3ty"><samp id="8g3ty"></samp></label>
  • <span id="8g3ty"></span>

    1. <center id="8g3ty"><optgroup id="8g3ty"></optgroup></center>
    2. <bdo id="8g3ty"><meter id="8g3ty"><bdo id="8g3ty"></bdo></meter></bdo><center id="8g3ty"><optgroup id="8g3ty"></optgroup></center>
      <label id="8g3ty"><samp id="8g3ty"></samp></label>

    3. 電子開發(fā)網(wǎng)

      電子開發(fā)網(wǎng)電子設(shè)計(jì) | 電子開發(fā)網(wǎng)Rss 2.0 會(huì)員中心 會(huì)員注冊(cè)
      搜索: 您現(xiàn)在的位置: 電子開發(fā)網(wǎng) >> 電子開發(fā) >> 單片機(jī) >> 正文

      逼真的蠟燭,ATtiny單片機(jī)電子蠟燭,ATtiny candle

      作者:佚名    文章來(lái)源:本站原創(chuàng)    點(diǎn)擊數(shù):    更新時(shí)間:2018-02-20

      ATtiny單片機(jī)電子蠟燭,ATtiny candle

      關(guān)鍵字:ATTINY85,電子蠟燭電路

      想想當(dāng)你好不容易跟女朋友共度燭光晚餐,卻因?yàn)橄灎T點(diǎn)沒了或打翻著火了,那是一件多么坑爹的事啊!今天為你分享一款自己diy的超自然的燭光蠟燭。
      WP_000356.jpg
      ATtiny 電子蠟燭,皮特•米爾斯開發(fā)這個(gè)偉大的蠟燭,正如我們圖片所見到的一樣,但怎樣讓這蠟燭的光芒像傳統(tǒng)的蠟燭一樣閃爍呢。
      WP_000370.jpg
      皮特使用一個(gè)高亮的LED和一些模擬的輔助軟件,這樣就使得ATtiny 電子蠟燭的燭光和傳統(tǒng)蠟燭擁有一樣的閃爍的燭光,并且優(yōu)于傳統(tǒng)蠟燭,因?yàn)樗话橛忻骰鸬奈kU(xiǎn)。
      WP_000376.jpg
      ATtiny 電子蠟燭最難的部分就閃爍神態(tài)逼真,所以皮特做了一個(gè)蠟燭光檢測(cè)電阻( LDR )和固定電阻作為一個(gè)分壓器。這是作為ATTINY85 ADC之中的一個(gè)輸入端,并離散時(shí)間間隔的進(jìn)行采樣。采樣速率為100毫秒。然后將采集的8bit的電頻值存儲(chǔ)到EEPROM中,以便記錄蠟燭的閃爍圖譜,驅(qū)動(dòng)將其連接的LED、PWM形成通路。在用三節(jié)干電池供電。最后您只需編程程序,然后通過(guò)開關(guān)進(jìn)行控制。
      WP_000345.jpg
      下面是ATtiny 電子蠟燭的電路圖
      ATTiny Candle Sch.jpg
      下面是程序的代碼以及寫入EEPROM的數(shù)據(jù)
       
      view plainprint?
      /* 
      Program Description: This program reads a light detecting resistor thru an internal ADC and stores the value,  
      after scaling it, to eeprom.  This ADC value is sent to a PWM channel with attached led.  This is essentially a data logger 
      for light and replay by LED.  If, if you aim the LDR at a flickering candle during its recording phase, you have a flickering  
      led candle.   
      A circuit description and other details can be found at http://petemills.blogspot.com 
      Filename: ATTiny_Candle_v1.0.c 
      Author: Pete Mills 
      Int. RC Osc. 8 MHz; Start-up time PWRDWN/RESET: 6 CK/14 CK + 64 ms 
      */  
      //********** Includes **********  
      #include        
      #include      
      #include   
      //********** Definitions **********  
      // LED for flame simulation  
      #define LED   PB0    
      #define LED_PORT PORTB  
      #define LED_DDR  DDRB  
      // Light Detecting Resistor for recording a live flame  
      #define LDR   PINB3   
      #define LDR_PORT PINB  
      #define LDR_DDR  DDRB  
      // Tactile Switch Input  
      #define SW1   PINB4  
      #define SW1_PORT PINB  
      #define SW1_DDR  DDRB  
      #define ARRAY_SIZE 500  // size of the flicker array  
      #define SAMPLE_RATE 100  // ms delay for collecting and reproducing the flicker  
      //********** Function Prototypes **********  
      void setup(void);  
      void toggle_led(void);  
      void program_flicker(void);  
      void led_alert(void);  
      void eeprom_save_array(void);  
      void eeprom_read_array(void);  
      void scale_array(void);  
      uint8_t get_adc(void);  
      uint8_t scale( uint8_t input, uint8_t inp_low, uint8_t inp_hi, uint8_t outp_low, uint8_t outp_hi);  
      uint8_t is_input_low(char port, char channel, uint8_t debounce_time, int input_block);  
      //********** Global Variables **********  
      uint8_t flicker_array[ ARRAY_SIZE ] = { 0 };  
      uint8_t EEMEM ee_flicker_array[ ARRAY_SIZE ] = { 0 };  
      int main(void)  
      {  
      uint16_t replay = 0;  
      setup();  
      eeprom_read_array();  
       while(1)  
       {   
        if( is_input_low( SW1_PORT, SW1, 25, 250 ) )  
        {  
         // program the flicker  
         // after entering and upon completion, a predetermined flash pattern will occur as described in led_alert()    
         // aim the ldr at a flickering candle or any other light source ( like a laser ) you want to record during this time  
         // and upon completion the values are stored to eeprom.  They are played back immediately as well   
         // as being recalled from eeprom upon first start up  
         led_alert();  
         program_flicker();  
         scale_array();  
         eeprom_save_array();  
         led_alert();  
        }  
        // replay the recorded flicker pattern   
        OCR0A = flicker_array[ replay ];  
        ++replay;  
        if( replay >= ( ARRAY_SIZE - 13 ) ) // if the end of the stored array has been reached  
        {   
         replay = 0;          // start again from the beginning  
         //led_alert();  
        }  
        _delay_ms( SAMPLE_RATE );  
        _delay_ms( 3 );    // ADC Conversion time  
       }  
      }  
      //********** Functions **********  
      void setup(void)  
      {  
       //********* Port Config *********  
       LED_DDR |= ( 1 << LED);   // set PB0 to "1" for output   
       LED_PORT &= ~( 1 << LED );   // turn the led off  
       LDR_DDR &= ~( 1 << LDR );   // set LDR pin to 0 for input  
       LDR_PORT |= ( 1 << LDR );   // write 1 to enable internal pullup  
       SW1_DDR &= ~( 1 << SW1 );   // set sw1 pin to 0 for input  
       SW1_PORT |= ( 1 << SW1 );   // write a 1 to sw1 to enable the internal pullup  
       //********** PWM Config *********  
       TCCR0A |= ( ( 1 << COM0A1 ) | ( 1 << WGM01 ) | ( 1 << WGM00 ) ); // non inverting fast pwm  
       TCCR0B |= ( 1 << CS00 ); // start the timer  
       //********** ADC Config **********  
       ADMUX |= ( ( 1 << ADLAR ) | ( 1 << MUX1 ) | ( 1 << MUX0 ) );  // left adjust and select ADC3  
       ADCSRA |= ( ( 1 << ADEN ) | ( 1 << ADPS2 ) | ( 1 << ADPS1 ) ); // ADC enable and clock divide 8MHz by 64 for 125khz sample rate  
       DIDR0 |= ( 1 << ADC3D ); // disable digital input on analog input channel to conserve power  
      }  
      void toggle_led()  
      {  
          LED_PORT ^= ( 1 << LED );  
      }  
      uint8_t is_input_low( char port, char channel, uint8_t debounce_time, int input_block )  
      {  
      /*  
      This function is for debouncing a switch input  
      Debounce time is a blocking interval to wait until the input is tested again.  
      If the input tests low again, a delay equal to input_block is executed and the function returns ( 1 )  
      */  
       if ( bit_is_clear( port, channel ) )  
       {  
        _delay_ms( debounce_time );  
         if ( bit_is_clear( port, channel ) )   
         {  
          _delay_ms( input_block );  
          return 1;  
         }  
       }  
       return 0;  
      }  
      uint8_t get_adc()  
      {  
       ADCSRA |= ( 1 << ADSC );   // start the ADC Conversion  
       while( ADCSRA & ( 1 << ADSC ));  // wait for the conversion to be complete  
       return ~ADCH; // return the inverted 8-bit left adjusted adc val  
      }  
      void program_flicker()  
      {   
       // build the flicker array  
       for( int i = 0; i < ARRAY_SIZE; i++ )  
       {  
        flicker_array[ i ] = get_adc();    
        _delay_ms( SAMPLE_RATE );  
       }  
      }  
      void led_alert()  
      {  
       // this is a function to create a visual alert that an event has occured within the program  
       // it toggles the led 10 times.  
       for( int i = 0; i < 10; i++ )  
       {  
        OCR0A = 0;  
        _delay_ms( 40 );  
        OCR0A = 255;  
        _delay_ms( 40 );  
       }  
      }  
      void eeprom_save_array()  
      {   
       for( int i = 0; i < ARRAY_SIZE; i++ )  
       {  
        eeprom_write_byte( &ee_flicker_array[ i ], flicker_array[ i ] );  
       }  
      }  
      void eeprom_read_array()  
      {  
       for( int i = 0; i < ARRAY_SIZE; i++ )  
       {  
        flicker_array[ i ] = eeprom_read_byte( &ee_flicker_array[ i ] );  
       }  
      }  
      uint8_t scale( uint8_t input, uint8_t inp_low, uint8_t inp_hi, uint8_t outp_low, uint8_t outp_hi)  
      {  
      return ( ( ( input - inp_low ) * ( outp_hi - outp_low ) ) / ( ( inp_hi - inp_low ) + outp_low ) );  
      }  
      void scale_array()  
      {  
       uint8_t arr_min = 255;  
       uint8_t arr_max = 0;  
       uint8_t out_low = 20;  
       uint8_t out_high = 255;  
       // find the min and max values  
       for( int i = 0; i < ARRAY_SIZE; i++ )  
       {  
        if( flicker_array[ i ] < arr_min )  
         arr_min = flicker_array[ i ];  
        if( flicker_array[ i ] > arr_max )  
         arr_max = flicker_array[ i ];  
       }  
       // now that we know the range, scale it  
       for( int i = 0; i < ARRAY_SIZE; i++ )  
       {  
        flicker_array[ i ] = scale( flicker_array[ i ], arr_min, arr_max, out_low, out_high );  
       }  
      }   igh );  
       }  
      }   igh );  
       }  
      }    
       }  
      }    
       }  
      }    
       }  
      }    }  
      }    }  
      }    }  
      }       
       
       
      EEPROM的數(shù)據(jù)
      rom.rar
      Tags:電子蠟燭  
      責(zé)任編輯:admin
    4. 上一篇文章:
    5. 下一篇文章: 沒有了
    6. 請(qǐng)文明參與討論,禁止漫罵攻擊,不要惡意評(píng)論、違禁詞語(yǔ)。 昵稱:
      1分 2分 3分 4分 5分

      還可以輸入 200 個(gè)字
      [ 查看全部 ] 網(wǎng)友評(píng)論
      關(guān)于我們 - 聯(lián)系我們 - 廣告服務(wù) - 友情鏈接 - 網(wǎng)站地圖 - 版權(quán)聲明 - 在線幫助 - 文章列表
      返回頂部
      刷新頁(yè)面
      下到頁(yè)底
      晶體管查詢
      主站蜘蛛池模板: 亚洲AV综合色区无码二区偷拍 | 亚洲综合区小说区激情区| 狠狠夜色午夜久久综合热91| 麻豆精品一区二区综合av| 久久婷婷五月综合色国产香蕉| 久久久久久久综合狠狠综合| 国产激情综合在线观看| 伊人yinren6综合网色狠狠| 久久国产综合精品五月天| 亚洲综合一区无码精品| 一本久道久久综合狠狠爱| 国产99久久亚洲综合精品| 丁香五月综合缴情综合| 人人妻人人狠人人爽天天综合网 | 久久久久久久综合日本| 亚洲 欧洲 日韩 综合在线| 狠狠色婷婷久久综合频道日韩| 国产成人综合亚洲绿色| 国产香蕉久久精品综合网| 亚洲综合无码一区二区| 久久久久青草大香线综合精品| 亚洲综合色视频在线观看| 色婷婷久久综合中文久久一本`| 亚洲综合一区二区| 亚洲欧洲日韩综合| 婷婷久久香蕉五月综合加勒比| 亚洲av综合av一区| 久久精品综合电影| 亚洲国产综合专区电影在线| 亚洲婷婷五月综合狠狠爱| 激情综合婷婷丁香五月| 色综合久久无码中文字幕| 91精品国产综合久久四虎久久无码一级| 久久婷婷综合色丁香五月| 天天综合天天综合| 久久综合亚洲色hezyo| 久久久久噜噜噜亚洲熟女综合| 激情五月激情综合网| 天天影视色香欲性综合网网站| 亚洲丁香婷婷综合久久| 亚洲综合伊人久久综合|