Added sunrise suport
This commit is contained in:
		
							parent
							
								
									d0ca835df2
								
							
						
					
					
						commit
						b4d1844b68
					
				
					 65 changed files with 6409 additions and 24 deletions
				
			
		
							
								
								
									
										61
									
								
								rgbled.cpp
									
										
									
									
									
								
							
							
						
						
									
										61
									
								
								rgbled.cpp
									
										
									
									
									
								
							|  | @ -5,10 +5,10 @@ RgbLed::RgbLed( Pwm8b* pwmA, Pwm8b* pwmB ): _pwmA(pwmA), _pwmB(pwmB) {} | |||
| void RgbLed::setSolidColor( const uint8_t r, const uint8_t g, const uint8_t b) | ||||
| { | ||||
|     _pattern=0; | ||||
|     _pwmA->setDutyA(g); | ||||
|     _pwmA->setDutyB(r); | ||||
|     _pwmB->setDutyB(b); | ||||
|     r+b+g == 0 ? off() : on(); | ||||
|     _targetR = r; | ||||
|     _targetG = g; | ||||
|     _targetB = b; | ||||
|     (!_fade &&  r+b+g == 0) ? off() : on(); | ||||
| } | ||||
| 
 | ||||
| void RgbLed::setPreset( const uint8_t preset) | ||||
|  | @ -79,6 +79,9 @@ void RgbLed::setPattern(const uint8_t id) | |||
|     _pattern=id; | ||||
|     if( id != 0 )  | ||||
|     { | ||||
|         _pwmA->setDutyB(0); | ||||
|         _pwmA->setDutyA(0); | ||||
|         _pwmB->setDutyB(0); | ||||
|         on(); | ||||
|         _stroke = false; | ||||
|         _counter = 0; | ||||
|  | @ -97,6 +100,11 @@ void RgbLed::off() | |||
|     _pwmB->off(); | ||||
| } | ||||
| 
 | ||||
| void RgbLed::setFade(bool fade) | ||||
| { | ||||
|     _fade=fade; | ||||
| } | ||||
| 
 | ||||
| void RgbLed::patternStep() | ||||
| { | ||||
|     if(_pattern == 1) | ||||
|  | @ -123,28 +131,65 @@ void RgbLed::patternStep() | |||
|     { | ||||
|         if(!_stroke)_counter++; | ||||
|         else _counter --; | ||||
|         if(_counter == 255 << 8) _stroke = true; | ||||
|         if(_counter == (uint8_t) 255 << 8) _stroke = true; | ||||
|         else if(_counter == 0) _stroke = false; | ||||
|         _pwmA->setDutyB(_counter >> 6); | ||||
|         _pwmA->setDutyA(_counter >> 8); | ||||
|         _pwmB->setDutyB(_counter >> 3); | ||||
|     } | ||||
|     else if(_pattern == 4) | ||||
|     { | ||||
|                                 ( _counter < 8192  )  ? _pwmA->setDutyB(_counter >> 6) : _pwmA->setDutyB( 128 + (_counter >> 11)); | ||||
|         if( _counter > 1024 )   (  8192 < _counter < 16384 )  ? _pwmA->setDutyA(_counter-8192 >> 6) : _pwmA->setDutyA( 128 + (_counter >> 9 )); | ||||
|         if( _counter > 8192 )   _pwmB->setDutyB(_counter >> 9); | ||||
|          | ||||
|         if(_counter<65530) _counter++; | ||||
|         else _pwmB->setDutyB(140); | ||||
|          | ||||
|         _delay_ms(18); //honey dose this make me look slow?
 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void RgbLed::logic() | ||||
| { | ||||
|     patternStep(); | ||||
|     if(_pattern == 0 && _fade) | ||||
|     { | ||||
|         _counter++; | ||||
|         if( uint8_t(_counter << _fadeSpeed) == 0) | ||||
|             { | ||||
|             if( getR() != _targetR) | ||||
|             { | ||||
|                 _pwmA->setDutyB(getR() - sgn(getR() - _targetR)); | ||||
|             } | ||||
|             if( getG() != _targetG) | ||||
|             { | ||||
|                 _pwmA->setDutyA(getG() - sgn(getG() - _targetG)); | ||||
|             } | ||||
|             if( getB() != _targetB) | ||||
|             { | ||||
|                 _pwmB->setDutyB(getB() - sgn(getB() - _targetB)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     else if(_pattern == 0) | ||||
|     { | ||||
|         _pwmA->setDutyA(_targetG); | ||||
|         _pwmA->setDutyB(_targetR); | ||||
|         _pwmB->setDutyB(_targetB); | ||||
|     } | ||||
|          | ||||
| } | ||||
| 
 | ||||
| uint8_t RgbLed::getR() | ||||
| { | ||||
|     return OCR0A; | ||||
|     return OCR0B; | ||||
| } | ||||
| uint8_t RgbLed::getB() | ||||
| { | ||||
|     return OCR0B; | ||||
|     return OCR2B; | ||||
| } | ||||
| uint8_t RgbLed::getG() | ||||
| { | ||||
|     return OCR2B; | ||||
|     return OCR0A; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 IMback
						IMback