SHARE
TWEET

Untitled

a guest Jul 15th, 2015 301 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int PIN_SCK = 12;
  2. int PIN_SDA = 11;
  3.  
  4. const int delayvalue = 10;
  5.  
  6. void setup(){
  7.     digitalWrite(PIN_SCK, 1); // I can first declare the state
  8.     digitalWrite(PIN_SDA, 1);
  9.     pinMode(PIN_SCK, OUTPUT); // then turn them on
  10.     pinMode(PIN_SDA, OUTPUT);
  11.  
  12.     delay(1000);
  13.  
  14.     digitalWrite(PIN_SDA, 0); // start bit
  15.  
  16.     shift_out(PIN_SDA, PIN_SCK, 0x50);
  17.     shift_out(PIN_SDA, PIN_SCK, 0xA9);
  18.     shift_out(PIN_SDA, PIN_SCK, 0xA9);
  19.  
  20.     digitalWrite(PIN_SDA, 1); // stop bit
  21.  
  22. }
  23.  
  24. void loop(){
  25.  
  26. }
  27. // uint8_t is the same as 8 bits aka one byte
  28. void shift_out(uint8_t datapin, uint8_t clockpin, uint8_t val){
  29.     uint8_t i;
  30.  
  31.     for (i = 0; i < 8; i++)  {
  32.         digitalWrite(datapin, !!(val & (1 << (7 - i))));
  33.         delay(1);
  34.         digitalWrite(clockpin, 0);
  35.         delay(delayvalue);
  36.         digitalWrite(clockpin, 1);
  37.         delay(delayvalue);
  38.     }
  39.  
  40.     digitalWrite(datapin, 0); // to enable stop bit
  41.     delay(100); // wait fro aknowledgement
  42.  
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top