Subversion Repositories HomeAutomation

Rev

Rev 289 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 289 Rev 291
Line 63... Line 63...
63
//Setting up OC1A, 16 bit counter used as 8 bit.
63
//Setting up OC1A, 16 bit counter used as 8 bit.
64
    /* Use OC1A */
64
    /* Use OC1A */
65
    TCCR1A |= (1<<COM1A1) | (1<<WGM11); /* Set OC1A at TOP, mode 14 */
65
    TCCR1A |= (1<<COM1A1) | (1<<WGM11); /* Set OC1A at TOP, mode 14 */
66
    TCCR1B |= (1<<WGM13) | (1<<WGM12) | (1<<CS11); /* Timer uses main system clock with 1/8 prescale */
66
    TCCR1B |= (1<<WGM13) | (1<<WGM12) | (1<<CS11); /* Timer uses main system clock with 1/8 prescale */
67
    ICR1 = 256; //8 bit precision to match the other two counters.
67
    ICR1 = 256; //8 bit precision to match the other two counters.
68
    OCR1A = 128;  //50% as standard
68
    OCR1A = 1;  //50% as standard
69
    DDRB |= (1<<PB1); /* Enable pin as output */
69
    DDRB |= (1<<PB1); /* Enable pin as output */
-
 
70
 
-
 
71
/* Use OC0A */
-
 
72
    TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00); /* Set OC0A at TOP, Mode 7 */
-
 
73
    TCCR0B |= (1<<CS02);//(1<<CS02)|(1<<CS00); /* Prescaler 1/1024 */
-
 
74
    OCR0A = 40;
-
 
75
    DDRD |= (1<<PD6);
-
 
76
 
-
 
77
/* Use OC0B */
-
 
78
    TCCR0A |= (1<<COM0B1);
-
 
79
    OCR0B = 40;
-
 
80
    DDRD |= (1<<PD5);
70
 
81
 
71
//Initialize variables
82
//Initialize variables
72
    fadeSpeed = 250;
83
    fadeSpeed = 250;
73
    dimSpeed = 255;
84
    dimSpeed = 255;
74
    timeStamp = 0;
85
    timeStamp = 0;
75
    dimStamp = 0;
86
    dimStamp = 0;
76
 
87
 
77
    Can_Message_t rxMsg;
88
    Can_Message_t rxMsg;
78
    currR = 0x3f;
89
    currR = 0x64;
79
    currG = 0x15;
90
    currG = 0x15;
80
    currB = 0x63;
91
    currB = 0x63;
81
 
92
 
82
    sei(); 
93
    sei(); 
83
 
94
 
84
    reformatRGB(currR,currG,currB);
95
    reformatRGB(currR,currG,currB);
85
 
96
 
86
    destR = 0xff;
-
 
87
    currIntens = 100;
97
    currIntens = 20;
88
    destIntens = 100;
98
    destIntens = 200;
89
 
99
 
90
    /* main loop */
100
    /* main loop */
91
    while (1) {
101
    while (1) {
92
        /* service the CAN routines */
102
        /* service the CAN routines */
93
        Can_Service();
103
        Can_Service();
Line 121... Line 131...
121
            }
131
            }
122
 
132
 
123
            if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x21)){
133
            if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x21)){
124
                program = 2;
134
                program = 2;
125
                fadeSpeed = 0;
135
                fadeSpeed = 0;
126
            }
136
            }
127
        }
137
        }
128
 
138
 
129
 
139
 
130
    }
140
    }
131
   
141
   
132
    return 0;
142
    return 0;
133
}
143
}
134
 
144
 
135
 
145
 
136
 
146
 
137
 
147
 
138
 
148
 
139
void updateLED(){
149
void updateLED(){
140
 
150
 
141
    OCR1A = currR * currIntens / 255;
151
//  OCR1A = currR * currIntens / 255;
142
    //TODO: Här ska givetvis de andra två färgerna också uppdateras.
152
    //TODO: Här ska givetvis de andra två färgerna också uppdateras.
143
 
153
 
144
   
154
   
145
    //Bara för debugcrap
155
    //Bara för debugcrap
146
    Can_Message_t txMsg;
156
    Can_Message_t txMsg;
147
    txMsg.Id = 0x55;
157
    txMsg.Id = 0x55;
148
    txMsg.RemoteFlag = 0;
158
    txMsg.RemoteFlag = 0;
149
    txMsg.ExtendedFlag = 1;
159
    txMsg.ExtendedFlag = 1;
Line 160... Line 170...
160
 
170
 
161
//Red
171
//Red
162
//Green
172
//Green
163
//Blue
173
//Blue
164
}
174
}
165
 
-
 
166
 
175
 
167
 
176
 
168
void reformatRGB(uint8_t R, uint8_t G, uint8_t B){
177
void reformatRGB(uint8_t R, uint8_t G, uint8_t B){
169
    uint8_t maxvalue;
178
    uint8_t maxvalue;
170
    uint16_t tempcontainer;
179
    uint16_t tempcontainer;