I am using NRF24L01 with Arduino Pro Mini to send data. All my pins are wired and I want to blink the LED with RX (pin 1). Can I do this? Below is my code. I always remove connections while uploading code from FTDI.
#include <SPI.h>
#include "Arduino.h"
#include <avr/sleep.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "LowPower.h"
RF24 radio(9, 10); // CE, CSN
const byte Surf1_address[6] = {'1' , 'P' , '0' , '1' , '1'};
#define BAUDRATE 115200
int jL, jR, ang, drive_sp, AM, AC, FR, arm_sp, ES, AL, AR, Aup, Alo, TRun, PA;
int n = 15;
int a[15];
int A[15];
//int digitalPins = 11;
int ar = 2, al = 3, am = 4, fr = 5, ac = 6, aup = 7, es = 8, alo = A2, pa = A0, trun = A1;
#define wakePin1 2
#define wakePin2 3
#define ledPin 1
unsigned long lastMillis = 0;
const long interval_1 = 1000;
const long interval_2 = 180000;
unsigned long currentTime1 = 0;
extern volatile unsigned long timer0_millis;
unsigned long new_value = 0;
void setup()
{
// Serial.begin(9600);
radio.begin();
radio.openWritingPipe(Surf1_address);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
radio.stopListening();
// pinMode(di, INPUT_PULLUP);
// pinMode(store,INPUT_PULLUP);
pinMode(ar, INPUT_PULLUP);
pinMode(al, INPUT_PULLUP);
pinMode(am, INPUT_PULLUP);
pinMode(fr, INPUT_PULLUP);
pinMode(ac, INPUT_PULLUP);
pinMode(aup, INPUT_PULLUP);
pinMode(es, INPUT_PULLUP);
pinMode(alo, INPUT_PULLUP);
pinMode(pa, INPUT_PULLUP);
pinMode(trun, INPUT_PULLUP);
pinMode(wakePin1, INPUT_PULLUP);
pinMode(wakePin2, INPUT_PULLUP);
digitalWrite(ledPin, LOW);
pinMode(ledPin, OUTPUT);
}
void loop() {
doBlink();
Read();
make_array( A, n );
send_data();
p_array();
{
if ((jL >= 500 && jL <= 550) && (jR >= 500 && jR <= 550) && (AC == 1) && (AM == 1) && (AR == 1) && (AL == 1) && (Aup == 1) && (Alo == 1) && (PA == 1)) {
Sleep_Mode();
}
else
setMillis(new_value);
}
}
void Read() {
PA = digitalRead(A0); // Type Feed
TRun = digitalRead(A1); // Test Run
Alo = digitalRead(A2); // Arm low
jR = analogRead(A3); // Right Joystick / Motor
jL = analogRead(A4); // Left Joystick / Motor
drive_sp = analogRead(A5); // Drive Speed
arm_sp = analogRead(A6); // Arm Speed
ang = analogRead(A7); //ang - Angle Control
// DI = digitalRead(0); // Momentary Direction change
AR = digitalRead(2); // ARM Right
AL = digitalRead(3); // ARM Left
AM = digitalRead(4); // Auto/Manual
FR = digitalRead(5); // FWD/REV
AC = digitalRead(6); // Arm Control
Aup = digitalRead(7); // Arm Up
ES = digitalRead(8); // Emmergency Switch
}
void make_array(int a[], int n)
{ int c = 0;
while (c < n)
{ for (int i = 0; i < 1; i++)
{ a[0] = jL; a[1] = jR; a[2] = ang; a[3] = drive_sp;
a[4] = arm_sp; a[5] = AC; a[6] = FR; a[7] = AM;
a[8] = ES; a[9] = AL; a[10] = AR;
a[11] = Aup; a[12] = Alo; a[13] = TRun;
a[14] = PA;
}
break;
}
}
void send_data()
{
radio.write( A , sizeof(A) );
}
void Sleep_Mode() {
{
unsigned long currentTime1 = millis();
if ((currentTime1 - lastMillis) > interval_2) {
attachInterrupt(0, wakePin1, LOW);
attachInterrupt(1, wakePin2, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(0);
detachInterrupt(1);
lastMillis = millis();
}
}
}
void setMillis(unsigned long new_millis) {
uint8_t oldSREG = SREG;
cli();
timer0_millis = new_millis;
SREG = oldSREG;
}
void doBlink() {
unsigned long currentMillis = millis();
if ((currentMillis - lastMillis) >= interval_1) {
digitalWrite(ledPin, HIGH);
delay(10);
lastMillis = currentMillis;
digitalWrite(ledPin, LOW);
}
}
void p_array()
{
Serial.print("Values transmitted are : ");
for (int i = 0 ; i < n ; i++ )
{
Serial.print(" | ");
Serial.print(A[i]);
}
Serial.print(" | "); Serial.println();
}