Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino Mega Sketch to drive strands and matrices of WS2801 pixels with Glediator.
- //(c)2012 by R. Heller
- //wwww.solderlab.de
- //Set Baudrate in Glediator to 1MBit !!!
- //Change this to YOUR matrix size!!
- #define Num_Pixels 16
- //Serial Data Output (Arduino-Mega Pin 6)
- #define SDO_Port PORTH
- #define SDO_DDR DDRH
- #define SDO_Pin 3
- //Serial Data Clock (Arduino-Mega Pin 7)
- #define CLK_Port PORTH
- #define CLK_DDR DDRH
- #define CLK_Pin 4
- //############################################################################################################################################################
- // Don't change anything upon here! #
- //############################################################################################################################################################
- #define Set_CLK_Low CLK_Port &= ~(1 << CLK_Pin)
- #define Set_CLK_High CLK_Port |= (1 << CLK_Pin)
- #define Set_CLK_Output CLK_DDR |= (1 << CLK_Pin)
- #define Set_SDO_Low SDO_Port &= ~(1 << SDO_Pin)
- #define Set_SDO_High SDO_Port |= (1 << SDO_Pin)
- #define Set_SDO_Output SDO_DDR |= (1 << SDO_Pin)
- #define CMD_NEW_DATA 1
- volatile unsigned char go = 0;
- void setup()
- {
- Set_SDO_Output;
- Set_CLK_Output;
- //Disable global interrupts
- cli();
- //UART Initialisation
- UCSR0A |= (1<<U2X0);
- UCSR0B |= (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
- UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00) ;
- UBRR0H = 0;
- UBRR0L = 1; //Baud Rate 1 MBit
- ptr=display_buffer;
- //Enable global interrupts
- sei();
- }
- void loop()
- {
- if (go==1) {shift_out_data(); go=0;}
- }
- //############################################################################################################################################################
- // USART-Interrupt-Prozedur (called every time one byte is compeltely received) #
- //############################################################################################################################################################
- ISR(USART0_RX_vect)
- {
- unsigned char b;
- b=UDR0;
- if (b == CMD_NEW_DATA) {
- Set_CLK_Low;
- delayMicroseconds(800); //Latch Data
- } else {
- shift_out_data(b);
- }
- }
- //############################################################################################################################################################
- // Shift out Data #
- //############################################################################################################################################################
- void shift_out_data(char b)
- {
- for (byte j=0; j<8; j++) {
- Set_CLK_Low;
- if (b & (1<<(7-j))) {Set_SDO_High;} else {Set_SDO_Low;}
- Set_CLK_High;
- }
- }
- //############################################################################################################################################################
- //############################################################################################################################################################
- //############################################################################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement