Advertisement
Guest User

Neopixel primer 3

a guest
Mar 19th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #define DDR_N (DDRB)
  2. #define PORT_N (PORTB)
  3. #define PIN_N (4)
  4.  
  5. #define BIT_SET (1 << PIN_N)
  6. #define BIT_CLR (B00000000)
  7.  
  8. #define PIXELS 16
  9.  
  10. unsigned char g = 0;
  11. unsigned char r = 0;
  12. unsigned char b = 10;
  13.  
  14. inline void T1H() { //12
  15.   asm volatile (  
  16.   "nop \n\t"
  17.   "nop \n\t"
  18.   "nop \n\t"
  19.   "nop \n\t"
  20.   "nop \n\t"
  21.   "nop \n\t"
  22.   "nop \n\t"
  23.   "nop \n\t"
  24.   "nop \n\t"  
  25.   "nop \n\t"
  26.   "nop \n\t"
  27.   //"nop \n\t"  
  28.   );
  29. }
  30.  
  31. inline void T1L() { //8
  32.   asm volatile (  
  33.   "nop \n\t"
  34.   "nop \n\t"
  35.   "nop \n\t"
  36.   "nop \n\t"
  37.   "nop \n\t"
  38.   "nop \n\t"
  39.   "nop \n\t"
  40.   //"nop \n\t"    
  41.   );
  42. }
  43.  
  44. inline void T0H() { //4
  45.   asm volatile (  
  46.   "nop \n\t"
  47.   "nop \n\t"
  48.   "nop \n\t"
  49.   //"nop \n\t"
  50.   );
  51. }
  52.  
  53. inline void T0L() { //12
  54.   asm volatile (  
  55.   "nop \n\t"
  56.   "nop \n\t"
  57.   "nop \n\t"
  58.   "nop \n\t"
  59.   "nop \n\t"
  60.   "nop \n\t"
  61.   "nop \n\t"
  62.   "nop \n\t"
  63.   "nop \n\t"  
  64.   "nop \n\t"
  65.   "nop \n\t"
  66.   //"nop \n\t"  
  67.   );
  68. }
  69.  
  70. inline void sendByte(unsigned char b) {
  71.   for (int bn = 7; bn >= 0; bn--) {
  72.     if (b & 1 << bn) {
  73.       PORT_N = BIT_SET;
  74.       T1H();
  75.       PORT_N = BIT_CLR;
  76.       T1L();
  77.     } else {
  78.       PORT_N = BIT_SET;
  79.       T0H();
  80.       PORT_N = BIT_CLR;
  81.       T0L();
  82.     }
  83.   }
  84. }
  85.  
  86. void setup() {
  87.   DDR_N = BIT_SET;
  88.    
  89.   for (int i = 0; i < PIXELS; i++) {
  90.     sendByte(g);
  91.     sendByte(r);
  92.     sendByte(b);        
  93.   }
  94.   delayMicroseconds(7);
  95. }
  96.  
  97. void loop() {
  98.   // put your main code here, to run repeatedly:
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement