Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void shiftOut(uint16_t val)
- {
- uint16_t i;
- for (i = 0; i < 16; i++) {
- if (!!(val & (1 << i)) PORTB |= (1 << SHIFT_DATA_PIN); //only pull the data pin high for.. 0's? 1's? whatever.
- PORTB |= (1 << SHIFT_CLK_PIN); // pulse the clock pin on
- PORTB &= ~(1 << SHIFT_CLK_PIN); // ... and off again
- PORTB &= ~(1 << SHIFT_DATA_PIN); // then set data pin back to low
- }
- }
- uint16_t convertforshiftout(uint8_t val)
- {
- uint16_t output = 0; // set output to all 000's
- output = ~output; // invert to all 111's
- uint8_t convertedvalue = val / 16; // turn our input into a value 0-15
- for (i = 0; i <= convertedvalue; i++) {
- output <<= 1; // shift to the left by one, adds a zero on the end
- }
- output = ~output; // invert output again, so we get 1111111111111111 for a very high value and 0000000011111111 for a halfway value and etc
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement