Recent Posts

Pages: [1] 2 3 ... 10
1
So, my code is evolving due to picking up things from tutorials like the one @robin2 posted..

Now if I press the button, the LED goes on and stays on without the ability to change.


Transmit..



Code: [Select]
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

int BUTTON = 5;
int val;
int old_val=0;
int msg[1];



byte state = 0;
byte brightness[] = {0, 75, 150, 255};

RF24 myRadio (9,10); // CNS, CE
bool radioNumber = 1;

byte addresses[][6] = {"1Node","2Node"};
bool role = 1;

void setup() {
 
 
  myRadio.begin();

  // Set the PA Level low to prevent power supply related issues since this is a
 // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  myRadio.setPALevel(RF24_PA_LOW);
 
  // Open a writing and reading pipe on each radio, with opposite addresses
 
    myRadio.openWritingPipe(addresses[1]);

}

void loop() {
   
  pinMode(BUTTON, INPUT);
 val=digitalRead(BUTTON); //check status of pushbutton
  if((val==HIGH)&&(old_val==LOW)) //button pressed
  {
    state++; //increment state
    delay(10); //debounce consideration
    if(state>4) //want only 4 brightness options
    {
      state=1;
      delay(5);
    }
  }
  old_val=val;
  if(state==1)
 
  {msg[0] = 0;
   
  }
  else if(state==2)
  {msg[0] = 75;
   
  }
  else if(state==3)
  {msg[0] = 150;
   
  }
  else if(state==4)
  {msg[0] = 255;
       
        myRadio.write(msg[1], 1);
    }
  }
 
 


 




Recieve...

Code: [Select]
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
RF24 myRadio (9, 10);
bool radioNumber = 0;
byte addresses[][6] = {"1Node","2Node"};
int msg[1];
int LED = 3;
bool role = 0;

void setup() {

pinMode(LED, OUTPUT);
Serial.begin(9600);
   myRadio.begin();

  // Set the PA Level low to prevent power supply related issues since this is a
 // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  myRadio.setPALevel(RF24_PA_LOW);
 
  // Open a writing and reading pipe on each radio, with opposite addresses
 
    myRadio.openReadingPipe(1, addresses[1]);
}

void loop() {

  if (myRadio.available())
  {
    while (myRadio.available())
    {
      myRadio.read(msg, 2);
    }
 analogWrite (LED, msg[0]);
   
    }
  }


I feel as if I'm spiraling.
2
Project Guidance / Re: humidifiers and led on rel...
Last post by TomGeorge - Today at 03:08 am
Hi,
Do you have a DMM?

Tom.. :)
3
General Discussion / Re: C# bitwise operation -> CR...
Last post by Unictu - Today at 03:06 am
The website I found about bitwise operators in C# shows that they are exactly the same as C, in which case they aren't difficult at all.
Not surprising. The "Arduino codes" don't work either. Where did you get that code from?

Pete

As a agriculture mechanical eng. everything in this field is difficult to me. To be honest, I can do ok with Arduino after a year or two tinkering. With other languages, especially C# which I have just started 2 days ago, it was a bit too much. That's where I am atm.

I was trying to replicate same operation for C# but found out byte array not supported so there seems to be no simple way to get it work. I tried to learn related C# information yesterday afternoon. I will keep trying, like right now on Sat afternoon, but hope someone can help me to the right direction. You Don't Know What You Don't Know.

The website I found about bitwise operators in C# shows that they are exactly the same as C, in which case they aren't difficult at all.
Not surprising. The "Arduino codes" don't work either. Where did you get that code from?

Pete

You are right, that Arduino code did not work. It was probably one of many attempts I was trying for C#. My mind got stuffed up on Friday afternoon sorry.

Original code from http://www.leonardomiliani.com/en/2013/un-semplice-crc8-per-arduino/

Code: [Select]

//CRC-8 - based on the CRC8 formulas by Dallas/Maxim
//code released under the therms of the GNU GPL 3.0 license
byte CRC8(const byte *data, byte len) {
  byte crc = 0x00;
  while (len--) {
    byte extract = *data++;
    for (byte tempI = 8; tempI; tempI--) {
      byte sum = (crc ^ extract) & 0x01;
      crc >>= 1;
      if (sum) {
        crc ^= 0x8C;
      }
      extract >>= 1;
    }
  }
  return crc;
}


Once again, appreciate any help.
4
The flash memory of the 328 micro can be flashed 10,000 times. So that's a possible cause for the verification error in avrdude. And that's how far my knowledge goes.

For the non-recognised Arduino, what does device manager in Windows (or the Mac equivalent, I'm not a Mac user) say?
5
Looks like it will have the authentic Dalek problem - can't climb stairs :)

...R
LOL


Z

6
Portugues / Re: Ajuda com Atoi e Serial.re...
Last post by tecdiego - Today at 02:59 am
CaioAssaf se você quiser, pode converter diretamente pelas funções do arduino.
https://www.arduino.cc/reference/en/language/variables/conversion/floatcast/

Lá tem mais funções para confirmar!
7
Programming Questions / Re: Adding EEPROM
Last post by PilotinControl - Today at 02:58 am
Thanks for being very descriptive as I've read through alot of the pros and cons of using eeprom versus external eeprom....This is being used on a model train layout so when the time to shut off the layout the eeprom would be used to save the state of the signals/block occupancy of the layout.....so I do not think it would run out any time soon of 100,000 saves etc. external would eliminate that possibility.
8
Programming Questions / count ch button presses withou...
Last post by BKK - Today at 02:54 am
I am trying to use the CH button on an IR remote to increment a variable by 1, count to 4 then reset to 0

the count needs to happen inside of an ISR, so I tried "delay(#)" and I also found millis does not work inside an ISR

the problem is that the system is dynamic, so delaying the button from incrementing cant really be done with a timer

when I push the button, no matter how quickly I try to do it, it increments at least 17 counts, I assume the program is looping through that fast.

here is a solution I got to work, but it is a little obtuse since it takes a while to begin, then it increments but not as predictably as I would like.

I think I am going to add a LED flash to tell the status (number) of the variable "CHButtonCounter" but is there a more sure way so the feedback is not necessarily needed?

thanx in advance, BKK

Code: [Select]

///Libraries///
#include <IRremote.h>                   // insert IRremote.h library

// IR pin connection
#define IRPin 2 // D2 IR Receiver output on D2 interrupt 1 pin

//interrupt set up
const byte interruptPin = 2;

//Blue position LED's
#define BlueLed1 A0  // blue LED in position A2 pin
#define BlueLed3 A3  // blue LED in position A3 pin
#define BlueLed5 3  // blue LED in position D3 pin
#define BlueLed7 A4  // blue LED in position A4 pin
#define BlueLed9 A5  // blue LED in position A5 pin on 6 pin header

//IR Remote button codes
#define IRButtonCH 16736925
#define IRButton1 16724175
#define IRButton3 16743045
#define IRButton5 16726215
#define IRButton7 16728765
#define IRButton9 16732845
#define RepeatValue 4294967295  //value broadcast by remote when button is held down


// IR Remote
IRrecv irrecv(IRPin);                 //define IR PIN for infrared receiver
volatile decode_results results;                  //define variable results to save the result of infrared receiver added volatile because it is interrupt routine
volatile int CHButtonCounter = 0 ;   // was 1 counter for the number of ch button presses volatile because it is in interrupt routine
volatile long LastButtonValue = 0;     // previous state of the button, holds value so it can compare if the remote button is held down volatile because it is in interrupt routine


//baud rate
#define BaudRate 9800  //was 115200

volatile char LedID = BlueLed5;
volatile int SkipCHcount = 0;

void setup()
{
  //IR receiver
  irrecv.enableIRIn();                      //Boot infrared decoding
  pinMode(IRPin, INPUT);                    // set pin to receive

  Serial.begin(BaudRate);

  //interupt setup
  attachInterrupt(digitalPinToInterrupt(interruptPin), IRinput, CHANGE);
}  //end setup

void loop() {

  Serial.println(CHButtonCounter);     // turn off and on to print value for trouble shooting, plot output to see representation of control

}//loop end

////////////////////////Functions//////////////////

//get IR input
void IRinput() {
  if (irrecv.decode(&results)) {
    if (results.value == RepeatValue)
      LastButtonValue = LastButtonValue;
    else
      LastButtonValue = results.value;
    irrecv.resume(); // Receive the next value
  }
  SkipCHcount = SkipCHcount + 1;
  if (SkipCHcount > 75) SkipCHcount = 1;
  if (SkipCHcount == 1) {
    //if CH is pressed, increment up until 5 which doesnt exist so resets to 1
    if (LastButtonValue == IRButtonCH) {  // if CH is pushed
      CHButtonCounter = CHButtonCounter + 1; //Ch button counter is incremented
    } //end if
    if (CHButtonCounter > 4) CHButtonCounter = 0;
  } //end if
}

9
Project Guidance / Re: Cheese cave control
Last post by Col68 - Today at 02:49 am
Too bad for me it did not work, I think I share the bad technical sheet, a little smoke started and I disconnect not damaged.

The only way that I manage to control for example an LED is when I connect a battery 3V with the negative on the G of the potentiometer and the R1 + L1 on the positive of the battery.

I can at this moment turn the potentiometer coter right and see the light of the led vary.

If I connect the positive of the battery with L2 / R2 of the potentiometer and the negative with the G of the potentiometer,

I can see the led vary with the potentiometer coter left.

I am lost with this module, the arm wrestling is difficult,
thank you for your help,
cordially.

10
General Discussion / Re: C# bitwise operation -> CR...
Last post by Unictu - Today at 02:47 am
Isn't that a question for a C# Forum ?

...R
I wasn't sure about category. Anyway, wonder if a Mod can help move it. Thank you.

Pages: [1] 2 3 ... 10