Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ArduinoShiftRegisters.ino
- //
- // for use at http://falstad.com/circuit/avr8js/
- //
- //
- #define DUR 50LU
- #define dataPin 8
- #define clockPin 9
- #define ActiveHi true
- int pass;
- inline void clk() {
- digitalWrite(clockPin, ActiveHi ? HIGH : LOW);
- delayMicroseconds(DUR);
- digitalWrite(clockPin, (!ActiveHi) ? HIGH : LOW);
- delayMicroseconds(DUR);
- }
- inline void shift_bit(bool const val) {
- digitalWrite(dataPin, val ? HIGH : LOW);
- delayMicroseconds(DUR);
- clk();
- }
- inline void shift_byte(uint8_t const val) {
- for (register int8_t i=0; i < 8; i++) {
- uint8_t bit = (val >> i) & 0x01;
- shift_bit(bit);
- }
- }
- inline void clear() {
- Serial.print("clearing..");
- for (int i=0; i < 7; i++) {
- shift_byte(0);
- }
- Serial.println("finished");
- }
- void setup() {
- Serial.begin(115200);
- // add external voltage (Javascript) with name "pin n" to access output pins
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- digitalWrite(clockPin, (!ActiveHi) ? HIGH : LOW);
- delayMicroseconds(DUR);
- clear();
- }
- void loop() {
- Serial.print("Pass ");
- Serial.println(++pass);
- shift_byte(0x3A); // 'o'
- shift_byte(0x2A); // 'n'
- shift_byte(0x20); // 'i'
- shift_byte(0x38); // 'u'
- shift_byte(0x7A); // 'd'
- shift_byte(0x0A); // 'r'
- shift_byte(0xEF); // 'A'
- delay(10);
- clear();
- // delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement