Top Banner

of 13

Stair Light Presentation

Apr 09, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/8/2019 Stair Light Presentation

    1/13

  • 8/8/2019 Stair Light Presentation

    2/13

    Hardware

    Arduino Uno

    Bread boardPush button

    LED

    Potentiometer

    TransistorRelay

    software

    Use AVR GCC (WinAVR )Programmers

  • 8/8/2019 Stair Light Presentation

    3/13

  • 8/8/2019 Stair Light Presentation

    4/13

    1. Light switch LED on, relay off

    Set the dimming time using pottentiometer2. Push a light switch (push button)3. Turn on the relay (with transistor)

    Start timer 0

    4. Start the LED dimming start timer 1

    5. After a while, turn off the relay.

  • 8/8/2019 Stair Light Presentation

    5/13

    //Turn on the lampPORTB = (1

  • 8/8/2019 Stair Light Presentation

    6/13

    while(1){

    //Turn off the LEDPORTB = 0x01;

    if(debounce(&PINB,PB3)){

    // set compare register initially to maximumOCR1A=ICR1;// set on the relay

    PB2=0X02//Timer/Counter1, Output Compare A Match Interrupt EnableTIMSK1 |=(1

  • 8/8/2019 Stair Light Presentation

    7/13

  • 8/8/2019 Stair Light Presentation

    8/13

    void initialise_timer0 (void){

    //Set Timer and prescaler to 8TCCR0B|=(1

  • 8/8/2019 Stair Light Presentation

    9/13

    void initialise_timer1 (void){

    //Clear OC1A/OC1B on Compare Match (Setoutput to low level).//select fast PWM//

    selecte prescaler to 8TCCR1A=((0x01

  • 8/8/2019 Stair Light Presentation

    10/13

    void ADC_initialize (void)

    {//select channel 2

    ADMUX|=(1

  • 8/8/2019 Stair Light Presentation

    11/13

    ISR(ADC_vect)

    {

    uint16_t data;

    data=ADCL;

    data+=(ADCH

  • 8/8/2019 Stair Light Presentation

    12/13

    static inline uint8_t debounce(volatile uint8_t *port, const uint8_tpin)

    {if(!(*port & (1

  • 8/8/2019 Stair Light Presentation

    13/13