Advertisement
Guest User

CCP,H,INO for 74hc595 (no extern)

a guest
Feb 1st, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. //*************** .H **************
  2.  
  3.  
  4. class LEDSR2 : ExportStreamListener {
  5.     private:
  6.         void onDcsBiosWrite(unsigned int address, unsigned int value);
  7.         unsigned char pin_;
  8.         unsigned int address_;
  9.         unsigned int mask_;
  10.         unsigned int * SRleds_;
  11.        
  12.     public:
  13.         LEDSR2(unsigned int address, unsigned int mask, char pin, unsigned int * SRleds);
  14. };
  15.  
  16.  
  17.  
  18.  
  19.  
  20. //************  .CPP  ***********
  21.  
  22. LEDSR2::LEDSR2(unsigned int address, unsigned int mask, char pin, unsigned int * SRleds) {
  23.     address_ = address;
  24.     mask_ = mask;
  25.     pin_ = pin;
  26.     SRleds_ = SRleds;
  27.    
  28. }
  29. void LEDSR2::onDcsBiosWrite(unsigned int address, unsigned int value) {
  30.     if (address_ == address) {
  31.         if (value & mask_) {
  32.             bitSet(*SRleds_, pin_);
  33.         } else {
  34.             bitClear(*SRleds_, pin_);
  35.         }
  36.     }
  37. }
  38.  
  39.  
  40. //*************** .INO SKETCH**************
  41.  
  42. [...]
  43.  
  44. unsigned int leds =0;
  45. unsigned int leds2 =0;
  46. unsigned int leds3 =0;
  47.  
  48.  
  49.  
  50. /**** Make your changes after this line ****/
  51. DcsBios::LEDSR2 gunReady(0x1026, 0x8000, 2, &leds);
  52. DcsBios::LEDSR2 canopyUnlocked(0x10da, 0x0004, 2, &leds2);
  53. DcsBios::LEDSR2 handleGearWarning(0x1026, 0x4000, 2, &leds3 );
  54.  
  55. [...]
  56.  
  57. void onDcsBiosWrite(unsigned int address, unsigned int value) {
  58.    if (address == 0xfffe) {
  59.         updateShiftRegister();
  60.     }
  61. }
  62.  
  63. void updateShiftRegister()
  64. {
  65.    digitalWrite(latchPin, LOW);
  66.    shiftOut(dataPin, clockPin, MSBFIRST, leds);
  67.    shiftOut(dataPin, clockPin, MSBFIRST, leds2);
  68.    shiftOut(dataPin, clockPin, MSBFIRST, leds3);
  69.    digitalWrite(latchPin, HIGH);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement