123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "io.h"
- #define PIN_DATA 1
- #define PIN_CLK 2
- #define PIN_ACK 0
- #define PIN_IN 4
- #define PIN_LED 3
- #include "bus.h"
- #include "timer.h"
- #ifndef __linux__
- void init_interrupt()
- {
- MCUSR = 0;
- wdt_disable();
- DDRB &= ~(1<<PB4); /* Set PB0 as input */
- PORTB |= (1<<PB4); /* Activate PULL UP resistor */
- PCMSK |= (1 << PCINT4); /* Enable PCINT0 */
- GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
- sei ();
-
- }
- #endif
- #include "VirtualWire.h"
- void init_rf()
- {
- //vw_set_tx_pin(transmit_pin);
- vw_set_rx_pin(0);
- //vw_set_ptt_pin(transmit_en_pin);
- vw_set_ptt_inverted(true); // Required for DR3100
- vw_setup(2000); // Bits per sec
- //pinMode(led_pin, OUTPUT);
- }
- void send_sync(void* data, int length)
- {
- vw_send((uint8_t *)data, length);
- vw_wait_tx();
- }
- const int led_pin = 11;
- const int transmit_pin = 0;
- const int receive_pin = 2;
- const int transmit_en_pin = 3;
- int count = 1;
- int main()
- {
- /*
- unsigned long last=0;
- unsigned long current_data = 0;
- bus_t bus;
- init();
- init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
- pinMode(PIN_IN, INPUT);
- pinMode(PIN_LED, OUTPUT);
- bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
- pinMode(PIN_IN, INPUT);
- while(1)
- {
- while(digitalRead(PIN_IN)) delay(1);
- while(!digitalRead(PIN_IN)) delay(1);
- current_data=micros()-last;
- if(current_data<10000) continue;
- last=micros();
- bus_write_sync(&bus, ¤t_data, 4);
- }
- *
- char salut[10] = "Salut ";
- init_rf();
- salut[7]=3;
- salut[8]=4;
- salut[9]=5;
- send_sync(salut, 10);*/
- vw_set_tx_pin(transmit_pin);
- vw_set_rx_pin(receive_pin);
- vw_set_ptt_pin(transmit_en_pin);
- vw_set_ptt_inverted(true); // Required for DR3100
- vw_setup(2000); // Bits per sec
- pinMode(led_pin, OUTPUT);
-
-
- char msg[7] = {'h','e','l','l','o',' ','#'};
- msg[6] = count;
- digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
- vw_send((uint8_t *)msg, 7);
- vw_wait_tx(); // Wait until the whole message is gone
- digitalWrite(led_pin, LOW);
- delay(1000);
- count = count + 1;
- }
|