|
|
- /*Digital Pin 2 is on PE4 (OC3B/INT4)*/
-
- #define PIN 2
- void setup() {
- // put your setup code here, to run once:
-
-
- /*define Pin 2/PE4 as output*/
- /*Libraries included w/arduino IDE*/
- DDRE = 0b00010000;
- }
-
- void loop() {
- // put your main code here, to run repeatedly:
-
- while(1){
- //sendPixel(0,0,0,10);
- //sendPixel(0,0,5);
- OneLittleRGBFunc(30);
- delay(1000);
- }
- }
- /*
- * Good way to see how fast your GPIO really is
- void PixHi (void){
- PORTE = 0b00010000;
- }
- void PixLow (void){
- PORTE = 0x00;
- }
- */
- void PixZero (void){
- PORTE = 0b00010000;
- //_delay_us(0.25);
- PORTE = 0x00;
- //_delay_us(0.25);
- }
- void PixOne (void){
- PORTE = 0b00010000;
- //_delay_us(0.55);
- _delay_us(0.55);
- PORTE = 0x00;
- }
- void PixBit (bool res){
-
- if (res == false){
- PixZero();
- }
- if (res == true){
- PixOne();
- }
-
- }
-
- void PixByte (char input){
- uint8_t changer = 0;
-
- //WS2812 reads bits as left is lowest (high in first), so go backwards
- for(changer=8;changer>0;changer--){
- PixBit(bitRead(input, changer));
- //input <<= 1; //Atmega didn't like this, so instead, using changer
- //instead of shifting input
- }
- }
-
- void sendPixel(uint8_t g, uint8_t r, uint8_t b){
-
- /*ws2812, reads bits left side as lowest*/
- /*PixByte(0b10100000); //This is dim green
- PixByte(0b00000000);
- PixByte(0b00000000);
- PixByte(0b00000000); //no white on my LED*/
-
-
- PixByte(g);
- PixByte(r);
- PixByte(b);
- //PixByte(w);
- PORTE = 0x00;
-
-
- }
-
- void OneLittleRGBFunc (uint8_t max){
- int rgbfunc = 0;
- for (rgbfunc = 0; rgbfunc < max; rgbfunc++){
- sendPixel(0,10,rgbfunc);
- delay(22);
- }
- for (rgbfunc = max; rgbfunc > 0; rgbfunc--){
- sendPixel(0,10,rgbfunc);
- delay(22);
- }
- }
-
-
-
-
-
|