Advertisement
igendel

The Arduino Kick Starter - Receiver Module

Feb 27th, 2015
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. // "The Arduino Kick Starter" Project
  2. // For ICStation.com's 2015 DIY competition
  3. // See it in action: https://www.youtube.com/watch?v=lrRGC9Ypedc
  4. // Code for Receiver Module
  5. // by Ido Gendel, 2015
  6. // Share and enjoy!
  7.  
  8. #include <VirtualWire.h>
  9.  
  10. const unsigned long DISPLAY_TIMEOUT = 5000;
  11.  
  12. byte charMap[14] = {0x00 /* None */,
  13.   0xFA /* 0 */ , 0x22 /* 1 */,
  14.   0xEC /* 2 */, 0xAE /* 3 */,
  15.   0x36 /* 4 */, 0x9E /* 5 */,
  16.   0xDE /* 6 */, 0x2A /* 7 */,
  17.   0xFE /* 8 */, 0xBE /* 9 */,
  18.   0x7E /* A */, 0x5C /* F */, 0xD0  /* L */
  19. };
  20.  
  21. uint8_t buf[VW_MAX_MESSAGE_LEN] = "";
  22. uint8_t buflen = VW_MAX_MESSAGE_LEN;
  23.  
  24. byte currDigit = 0;
  25. unsigned long lastChange = 0;
  26.  
  27. void setup()
  28. {
  29.     for (byte j = 3; j < 11; j++) {
  30.       pinMode(j, OUTPUT);
  31.       digitalWrite(j, LOW);
  32.     }
  33.  
  34.     for (byte j = A0; j < A4; j++) {
  35.       pinMode(j, OUTPUT);
  36.       digitalWrite(j, HIGH);
  37.     }  
  38.  
  39.     // Initialise the IO and ISR
  40.     vw_set_tx_pin(A5);
  41.     vw_set_rx_pin(12);
  42.     vw_set_ptt_inverted(true); // Required for DR3100
  43.     vw_setup(2000);  // Bits per sec
  44.  
  45.     vw_rx_start();       // Start the receiver PLL running
  46. }
  47.  
  48. byte getCharMap(const char c) {
  49.  
  50.   if ((c >= '0') && (c <= '9')) return charMap[c - 47];
  51.   if (c == 'A') return charMap[11];
  52.   if (c == 'F') return charMap[12];
  53.   if (c == 'L') return charMap[13];  
  54.   return charMap[0];
  55.  
  56. }
  57.  
  58. void drawNextDigit() {
  59.  
  60.   char cm;
  61.  
  62.   currDigit = (currDigit + 1) & 3;
  63.   cm = getCharMap(buf[3 - currDigit]);
  64.   PORTC |= 0x0F; // all digits HIGH (clear)
  65.  
  66.   PORTD = (PORTD & 0x07) + (cm & 0xF8); //  pins 3-7
  67.   PORTB = (PORTB & 0xF8) + (cm & 7); // pins 8-10
  68.  
  69.   PORTC -= (1 << currDigit); // current digit LOW (show)
  70.  
  71. }
  72.  
  73. void loop()
  74. {
  75.  
  76.     if (vw_get_message(buf, &buflen)) // Non-blocking
  77.     {
  78.        lastChange = millis();
  79.     }
  80.  
  81.     if (millis() - lastChange < DISPLAY_TIMEOUT) drawNextDigit();
  82.      else PORTC |= 0x0F; // all digits HIGH (clear)
  83.     delay(1);
  84.    
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement