attiny_spi_Client.ino 986 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #define BUTTON 4
  2. #include <NRF24.h>
  3. #include <SoftSpi.h>
  4. NRF24 nrf24(10,SS);
  5. uint8_t data[1];
  6. void setup()
  7. {
  8. pinMode(BUTTON, OUTPUT);
  9. digitalWrite(BUTTON, LOW);
  10. delay(1000);
  11. if (!nrf24.init())
  12. digitalWrite(BUTTON, HIGH);
  13. if (!nrf24.setChannel(20))
  14. digitalWrite(BUTTON, HIGH);
  15. if (!nrf24.setThisAddress((uint8_t*)"clie1", 5))
  16. digitalWrite(BUTTON, HIGH);
  17. if (!nrf24.setPayloadSize(1))
  18. digitalWrite(BUTTON, HIGH);
  19. if (!nrf24.setRF(NRF24::NRF24DataRate2Mbps, NRF24::NRF24TransmitPower0dBm))
  20. digitalWrite(BUTTON, HIGH);
  21. nrf24.spiWriteRegister(NRF24_REG_06_RF_SETUP, NRF24_CONT_WAVE | NRF24_PLL_LOCK | NRF24_PWR_0dBm);
  22. if (!nrf24.powerUpTx())
  23. digitalWrite(BUTTON, HIGH);
  24. }
  25. // With printing commented and delay removed, this can achieve about 666 round trips per second
  26. void loop()
  27. {
  28. nrf24.setTransmitAddress((uint8_t*)"servl",5);
  29. data[0]=1;
  30. nrf24.send(data, (uint8_t)1);
  31. delay(1000);
  32. data[0]=2;
  33. nrf24.send(data, (uint8_t)1);
  34. delay(1000);
  35. }