Im looking for a Help

Hi, I'm looking for some help, I'm using EEPROM (internal atmega328p), my code is:

void loop() {
int analogin= analogRead(A0);
if(analogin<20){
  EEPROM.write(dev1addr,dev1st);
  EEPROM.write(dev2addr,dev2st);
  EEPROM.write(dev3addr,dev3st);
  EEPROM.write(dev4addr,dev4st);
  EEPROM.write(dev5addr,dev5st);
  EEPROM.write(dev6addr,dev6st);
  EEPROM.write(dimmeraddr,currentspeed);
  EEPROM.write(dimmer2addr,currentspeed);
Serial.println("Point 1");
delay(20000);
}
}

now i want to use STOP command instead of delay or long delay, i want EEPROM write everthing and then stop and didnt write anything until analogin<20 again

@Delta_G Help me. I'm lost. I see no evidence the OP revised his post, yet I don't see "while" anywhere in the code they posted.

The "while" is implied in the question. "didnt write anything until analogin<20 again"

Sorry, crystal ball needs washing. Carry on.

But I bet it is still NOT what the OP wants to happen.

This does not make sense. What if "analogin" is always < 20?

If you are having trouble with the language, use Google translate to put together a better description of what your project is about, and what you want the code to do.

I was going to give him an easy solution pull the plug.

1 Like

Sorry language problem

I want to use the STOP command instead of a delay or a long delay, I want the EEPROM to write everything and then stop and not write anything until the analog pin reaches 255 and then again analog <20.

In simple words ........... write once in every .......... analog <20.

Or can I put this section in VOID SETUP instead of VOID LOOP?

Could someone please shed some light on this? I realize there's a language barrier in play, but I'm not familiar with any STOP command in the Arduino context.

My point is not to write again until the analog value becomes 1023 (5v) and then drops below 20 again. (Write only once when the analog value is less than 20 until next time)

Can you please edit code ..... im new in coding and mostly use gpt for coding

This is my whole code

#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <IRremote.h>

#define code1 0xF720DF      //Code for Dev 1....
#define code2 0xF7A05F      //Code for Dev 2....

   
SoftwareSerial EspSerial(0, 1); //TX, RX respetively
int RECV_PIN = 2; //data out of IR receiver connects to pin 2

IRrecv irrecv(RECV_PIN);

decode_results results;

String device;
bool dev1st,dev2st;
const int dev1addr=2, dev2addr=4;

const int dev1 = 8;
const int dev2 = 7; //PWM

//-----------------------------------------------------------------------//  
void setup() {
  pinMode(A0,INPUT);
  pinMode(dev1, OUTPUT);
  pinMode(dev2, OUTPUT);
 

  dev1st=EEPROM.read(dev1addr);
  dev2st=EEPROM.read(dev2addr);
 
  digitalWrite(dev1,dev1st);
  digitalWrite(dev2,dev2st);
  
  EspSerial.begin(9600);
    irrecv.enableIRIn();
    Serial.begin(9600);
  printstatus();

}

//bool led1st, led2st;
//-----------------------------------------------------------------------//  
void loop() {

  int analogin= analogRead(A0);
  if(analogin<20){
    EEPROM.write(dev1addr,dev1st);
    EEPROM.write(dev2addr,dev2st);
  Serial.println("Point 1");    
  delay(200000);
  }
  if (irrecv.decode(&results)) {



  irrecv.resume();

  if (results.value == code1){ //Code to turn the LED ON/OFF
      if(!dev1st){ // if the LED was turned off, then we turn it on 
        digitalWrite(dev1,HIGH);
        dev1st=1; //LED is now turned on
      }
      else{
        digitalWrite(dev1,LOW); //if the LED was turned on, then we turn it off
        dev1st=0;
      }
      }
      
      else if (results.value == code2){ //Code to turn the LED ON/OFF
      if(!dev2st){ // if the LED was turned off, then we turn it on 
        digitalWrite(dev2,HIGH);
        dev2st=1; //LED is now turned on
      }
      else{
        digitalWrite(dev2,LOW); //if the LED was turned on, then we turn it off
        dev2st=0; 
      }}
    }

  else{
  if (EspSerial.available()){  //Check if there is an available byte to read
    delay(10); //Delay added to make thing stable 
    device = EspSerial.readString(); //Conduct a serial read
    }  
    if (device.length() > 0) {
  Serial.print("Data =");    
  Serial.println(device); 
  if (device == "/1on") {digitalWrite(dev1, HIGH);dev1st=1;}
      else if (device == "/1off") {digitalWrite(dev1, LOW);dev1st=0;}
      else if (device == "/2on") {digitalWrite(dev2, HIGH);dev2st=1;}
      else if (device == "/2off") {digitalWrite(dev2, LOW);dev2st=0;}

      else if(device == "/w"){
        printstatus();
        }
  else{
  Serial.println("Point 3");
}     
//-----------------------------------------------------------------------//  
  device="";}}
  }

void printstatus(){
 float percentspeed;
  Serial.print("Device 1= ");
  Serial.println(dev1st);
  Serial.print("Device 2= ");
  Serial.println(dev2st);
}

now my question: this code works well on IRremote.h, how to modify this code for IRremote.hpp (new version of IR library)??

old library: 2.8.0
New library: 4.3.1

on old library IR code look like this: 0xF720DF
on new one: Protocol=NEC Address=0xEF00 Command=0x4 Raw-Data=0xFB04EF00 32 bits LSB first
Send with: IrSender.sendNEC(0xEF00, 0x4, );

please help me

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.