Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // "The Arduino Kick Starter" Project
- // For ICStation.com's 2015 DIY competition
- // See it in action: https://www.youtube.com/watch?v=lrRGC9Ypedc
- // Code for Receiver Module
- // by Ido Gendel, 2015
- // Share and enjoy!
- #include <VirtualWire.h>
- const unsigned long DISPLAY_TIMEOUT = 5000;
- byte charMap[14] = {0x00 /* None */,
- 0xFA /* 0 */ , 0x22 /* 1 */,
- 0xEC /* 2 */, 0xAE /* 3 */,
- 0x36 /* 4 */, 0x9E /* 5 */,
- 0xDE /* 6 */, 0x2A /* 7 */,
- 0xFE /* 8 */, 0xBE /* 9 */,
- 0x7E /* A */, 0x5C /* F */, 0xD0 /* L */
- };
- uint8_t buf[VW_MAX_MESSAGE_LEN] = "";
- uint8_t buflen = VW_MAX_MESSAGE_LEN;
- byte currDigit = 0;
- unsigned long lastChange = 0;
- void setup()
- {
- for (byte j = 3; j < 11; j++) {
- pinMode(j, OUTPUT);
- digitalWrite(j, LOW);
- }
- for (byte j = A0; j < A4; j++) {
- pinMode(j, OUTPUT);
- digitalWrite(j, HIGH);
- }
- // Initialise the IO and ISR
- vw_set_tx_pin(A5);
- vw_set_rx_pin(12);
- vw_set_ptt_inverted(true); // Required for DR3100
- vw_setup(2000); // Bits per sec
- vw_rx_start(); // Start the receiver PLL running
- }
- byte getCharMap(const char c) {
- if ((c >= '0') && (c <= '9')) return charMap[c - 47];
- if (c == 'A') return charMap[11];
- if (c == 'F') return charMap[12];
- if (c == 'L') return charMap[13];
- return charMap[0];
- }
- void drawNextDigit() {
- char cm;
- currDigit = (currDigit + 1) & 3;
- cm = getCharMap(buf[3 - currDigit]);
- PORTC |= 0x0F; // all digits HIGH (clear)
- PORTD = (PORTD & 0x07) + (cm & 0xF8); // pins 3-7
- PORTB = (PORTB & 0xF8) + (cm & 7); // pins 8-10
- PORTC -= (1 << currDigit); // current digit LOW (show)
- }
- void loop()
- {
- if (vw_get_message(buf, &buflen)) // Non-blocking
- {
- lastChange = millis();
- }
- if (millis() - lastChange < DISPLAY_TIMEOUT) drawNextDigit();
- else PORTC |= 0x0F; // all digits HIGH (clear)
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement