Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Programming Questions / Re: Atmega8 16PU Delay Problem on: March 04, 2012, 10:19:02 am


I am using Arduino-1.0 Ver
and I  selected  Arduino NG or older w/Atmega8
32  Using Arduino / Programming Questions / Re: Atmega8 16PU Delay Problem on: March 04, 2012, 09:47:22 am

Sir,

First I uploaded this program:
Code:


#include <EEPROM.h>

// CONSTANTS
// INPUT PINS
#define ReedSwA1  6  //Tank1 Level1
#define ReedSwA2  7  //Tank1 Level2
#define ReedSwA3  8  //Tank1 Level3
#define AutoMan   10 //Auto/manual button
// OUTPUT PINS
#define ledpinA1  2 //Tank1 Level1 Display
#define ledpinA2  3 //Tank1 Level2 Display
#define ledpinA3  4 //Tank2 Level1 Display
#define AutoManLed  11  //Auto/manual operation
#define RelayPIN 12 // Pin for water pump activation

// EEPROM MEMORY POSITIONS
#define memposL1  2  // set constant eeprom position 0 to save Level1

// variables
int state=0;
int level = 0;
int lastlevel = 0;

void setup (){
pinMode(AutoMan,INPUT);            // default mode is INPUT
pinMode(ReedSwA1,INPUT);            // default mode is INPUT
pinMode(ReedSwA2,INPUT);            // default mode is INPUT
pinMode(ReedSwA3,INPUT);            // default mode is INPUT

digitalWrite(AutoMan, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA1, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA2, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA3, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH


pinMode(RelayPIN, OUTPUT);
pinMode(ledpinA1, OUTPUT);
pinMode(ledpinA2, OUTPUT);
pinMode(AutoManLed, OUTPUT);
pinMode(ledpinA3, OUTPUT);


// Restore tank water Level from eeprom
level = EEPROM.read(memposL1); // Read from eeprom memPos1 the value of Level1
lastlevel = level;                        // also update the according lastLevel variable
if ((level == 0)||(level>3)) { // if eeprom has illegal value
level=1; // set level to 1 (minimum)
updateprom(); // call updateprom function to set eeprom memory value to minimum too.
}
setleds(); // restore the reed states from EEPROM stored value.
delay(1000);
startstoppump();
}


void setleds() {
  digitalWrite(ledpinA1, LOW );
  digitalWrite(ledpinA2, LOW );
  digitalWrite(ledpinA3, LOW );
  if (level > 0)   digitalWrite(ledpinA1, HIGH );
  if (level > 1)   digitalWrite(ledpinA2, HIGH );
  if (level > 2)   digitalWrite(ledpinA3, HIGH );
 }

void  startstoppump(){
  if (level < 3)   digitalWrite(RelayPIN, HIGH );
  if ((level == 3) & (state == 0)) {
    digitalWrite(RelayPIN, LOW );
}
else {
    digitalWrite(RelayPIN, HIGH );
}
}

void updateprom() {
  // UPDATE LEVEL 1
lastlevel = level;      // update lastLevel variable
EEPROM.write(memposL1, level);   // and store new Level value to eeprom
}

void loop () {
  if ( (digitalRead(AutoMan) == LOW) & (state == 0) ) { // Button  pushed
         state=1; 
         digitalWrite(AutoManLed, state );        // Turn on the LED
         startstoppump();
         delay(400);
  }
 
  if ( (digitalRead(AutoMan) == LOW) & (state == 1)  ) { // Button  pushed
         state=0; 
         digitalWrite(AutoManLed, state );        // Turn off the LED
         startstoppump();
         delay(400);
   }
 
  if ( digitalRead(ReedSwA1) == LOW  ) { // Button  pushed
 level = 1;
 }
 
  if ( digitalRead(ReedSwA2) == LOW  ) { // Button  pushed
 level = 2;
 }

  if ( digitalRead(ReedSwA3) == LOW  ) { // Button  pushed
 level = 3;
 }

 
 if (level != lastlevel) {
   setleds();
   startstoppump();
   updateprom();
 }   
 
}

When this problem started then I tried Examples------Basic-----Blink Program, same problem existing


33  Using Arduino / Project Guidance / Loading images in the post on: March 04, 2012, 09:08:19 am
Hello There !

How I can upload images in the post ?

Harnam
34  Using Arduino / Programming Questions / Atmega8 16PU Delay Problem on: March 04, 2012, 08:31:39 am
 Hi There !

The code which I upload in Atmega328P works OK but when the same code uploaded in Atmega8 16PU works
with a delay  smiley-mad . The Board I am using is Arduino Duemilanove. I have tried  it in other boards with a crystal 16 MHz also But this problem of delay exists.

Please help me to resolve this problem.



Harnam
35  Using Arduino / Project Guidance / ultrasonic transducer for water level on: January 05, 2012, 01:42:21 am

Need ideas  to make a accurate and affordable ultrasonic transducer range approx. 2 mtrs for domestic  water tank level
with sharp GP2D120 or some other cheap sensors.


Thanks in advance
36  Using Arduino / Programming Questions / Pump Starting Problem on: December 15, 2011, 04:21:20 am
Hi there !
My main object is to start the pump when the water level in tank
falls below the Level 1 but in the following code the pump starts
at level 2,Please help me to correct this problem.


Code:
#include <EEPROM.h>

// CONSTANTS
// INPUT PINS
#define ReedSwA1  6  //Tank1 Level1
#define ReedSwA2  7  //Tank1 Level2
#define ReedSwA3  8  //Tank1 Level3
#define AutoMan   10 //Auto/manual button
// OUTPUT PINS
#define ledpinA1  2 //Tank1 Level1 Display
#define ledpinA2  3 //Tank1 Level2 Display
#define ledpinA3  4 //Tank2 Level1 Display
#define AutoManLed  11  //Auto/manual operation
#define RelayPIN 12 // Pin for water pump activation

// EEPROM MEMORY POSITIONS
#define memposL1  2  // set constant eeprom position 0 to save Level1

// variables
int state=0;
int level = 0;
int lastlevel = 0;

void setup (){
pinMode(AutoMan,INPUT);            // default mode is INPUT
pinMode(ReedSwA1,INPUT);            // default mode is INPUT
pinMode(ReedSwA2,INPUT);            // default mode is INPUT
pinMode(ReedSwA3,INPUT);            // default mode is INPUT

digitalWrite(AutoMan, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA1, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA2, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH
digitalWrite(ReedSwA3, HIGH);     // Turn on the internal pull-up resistor, default state is HIGH


pinMode(RelayPIN, OUTPUT);
pinMode(ledpinA1, OUTPUT);
pinMode(ledpinA2, OUTPUT);
pinMode(AutoManLed, OUTPUT);
pinMode(ledpinA3, OUTPUT);


// Restore tank water Level from eeprom
level = EEPROM.read(memposL1); // Read from eeprom memPos1 the value of Level1
lastlevel = level;                        // also update the according lastLevel variable
if ((level == 0)||(level>3)) { // if eeprom has illegal value
level=1; // set level to 1 (minimum)
updateprom(); // call updateprom function to set eeprom memory value to minimum too.
}
setleds(); // restore the reed states from EEPROM stored value.
delay(1000);
startstoppump();
}


void setleds() {
  digitalWrite(ledpinA1, LOW );
  digitalWrite(ledpinA2, LOW );
  digitalWrite(ledpinA3, LOW );
  if (level > 0)   digitalWrite(ledpinA1, HIGH );
  if (level > 1)   digitalWrite(ledpinA2, HIGH );
  if (level > 2)   digitalWrite(ledpinA3, HIGH );
 }

void  startstoppump(){
 [color=red]if (level < 1)   digitalWrite(RelayPIN, HIGH );[/color]
  if ((level == 3) & (state == 0)) {
    digitalWrite(RelayPIN, LOW );
}
else {
    digitalWrite(RelayPIN, HIGH );
}
}

void updateprom() {
  // UPDATE LEVEL 1
lastlevel = level;      // update lastLevel variable
EEPROM.write(memposL1, level);   // and store new Level value to eeprom
}

void loop () {
  if ( (digitalRead(AutoMan) == LOW) & (state == 0) ) { // Button  pushed
         state=1; 
         digitalWrite(AutoManLed, state );        // Turn on the LED
         startstoppump();
         delay(400);
  }
 
  if ( (digitalRead(AutoMan) == LOW) & (state == 1)  ) { // Button  pushed
         state=0; 
         digitalWrite(AutoManLed, state );        // Turn off the LED
         startstoppump();
         delay(400);
   }
 
  if ( digitalRead(ReedSwA1) == LOW  ) { // Button  pushed
 level = 1;
 }
 
  if ( digitalRead(ReedSwA2) == LOW  ) { // Button  pushed
 level = 2;
 }

  if ( digitalRead(ReedSwA3) == LOW  ) { // Button  pushed
 level = 3;
 }

 
 if (level != lastlevel) {
   setleds();
   startstoppump();
   updateprom();
 }   
 
}

37  Using Arduino / Programming Questions / Re: 'void' does not name type on: August 14, 2011, 08:29:40 pm
Hello there !

This code displays the levels 25%,50%,Min,75% without activating the buttonpins with time delay and Level Max is missing.It does not display coressponding to the states of the button pins. There is no effect in the displays even the buttonpins are switched ON or OFF.

I am writing to the EEPROM the state of the levels. Is it because of EEPROM write or something else ??
Please help !!

Code:
#include <LiquidCrystal.h>
#include <EEPROM.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2); //when LCD is used//pins

const byte buttonpin1 = 6; // reed switch 1
const byte buttonpin2 = 7; // reed switch 2
const byte buttonpin3 = 8; // reed switch 3
const byte buttonpin4 = 9; // reed switch 4
const byte buttonpin5 = 10; // reed switch 5

byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;
byte state5 = 0;
int Level = 0;
void setup() {
 //configure pins   
  pinMode(buttonpin1, INPUT);
  pinMode(buttonpin2, INPUT);
  pinMode(buttonpin3, INPUT);
  pinMode(buttonpin4, INPUT);
  pinMode(buttonpin5, INPUT);

  //setup LCD, when lcd used

  lcd.begin (16,2);

  //intitial message

  lcd.setCursor (0,0);
  lcd.print ("Hello Arduino");

  Level = EEPROM.read(0); // read level value from eeprom.
  //Recalling the Level from eeprom .

  lcd.setCursor (0,1);
  lcd.print ("Last level: ");
  lcd.print (Level);
  delay(5000);
  lcd.clear();

  // Create custom characters to make a ramp
  byte clrChar[8] = { // character needed to clear others
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000
  };
  lcd.createChar(0, clrChar);

 byte newChar[8] = { // // black character
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111
  };
 lcd.createChar(1, newChar);
}
 
//Make the display a single function called from inside loop simplifying // the code to fix graph and states.

  void display() {
  switch (Level) {
  case 1:
    state1 = 0;
    state2 = 1;
    state3 = 1;
    state4 = 1;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("MIN");// write text next to graph
    break;
  case 2:
    state1 = 0;
    state2 = 0;
    state3 = 1;
    state4 = 1;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("25%");// write text next to graph
    break;
  case 3:
    state1 = 0;
    state2 = 0;
    state3 = 0;
    state4 = 1;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("50%");// write text next to graph
    break;

  case 4:
    state1 = 0;
    state2 = 0;
    state3 = 0;
    state4 = 0;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("75%");// write text next to graph
    break;
  case 5:
    state1 = 0;
    state2 = 0;
    state3 = 0;
    state4 = 0;
    state4 = 0;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.write(1); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("MAX%");// write text next to graph
    break;

    //default:
    // if nothing else matches, do the default
    // default is optional
  }
}

void loop(){

  display();  // display is called at everyloop and at beginning of it.
  //So at first time will restore the Display and states from the Level stored at eeprom.

  if (digitalRead(buttonpin1) == LOW){ // min
    int state1= digitalRead(buttonpin1);
    Level=1;
    delay(500);  // debounce
  }
  if (digitalRead(buttonpin2) == LOW) // 25%
  {
    state2 = !state2;  // toggle state
    if (state2 >0 ){
      Level = 2;
    }
      if (state2 ==0 ){
        Level =1;
    }
      delay(500);  // debounce
    }

 if (digitalRead(buttonpin3) == LOW) //50%
    {
      state3 = !state3;  // toggle state
      if (state3 >0 ){
        Level = 3;
      }
      if (state3 ==0 ){
        Level = 2;
      }
      delay(500);  // debounce
      }

 if (digitalRead(buttonpin4) == LOW) // 75%
      {
      state4 = !state4;  // toggle state
      if (state4 >0 ){
        Level = 4;
      }
      if (state4 ==0 ){
        Level = 3;
      }
      delay(500);  // debounce
      }

 if (digitalRead(buttonpin5) == LOW) { // max
      state5 = !state5;  // toggle state
      Level = 5;
      // CUT POWER SUPPLY TO PUMP.
      delay(500);  // debounce
      }

  if (digitalRead(buttonpin5) == HIGH) {  // max reed off
      state5 = !state5;  // toggle state
      if (state5>1) {
        Level = 4;
      }
      delay(500);  // debounce
      }
    Level=state1+state2+state3+state4+state5;
    EEPROM.write(0, Level); // Write to eeprom memory position 0 the Level value.

     //delay(100); // small delay at each loop.
      }

38  Using Arduino / Programming Questions / Re: 'void' does not name type on: August 14, 2011, 02:23:11 am

I have corrected the "case" problem

Quote
Do you have pull-up resistors on all these pins?
10K pull up resistors are connected to all these pins

Quote
You will wear it out in a couple of seconds. Try only writing to it if the level changes, or perhaps only every minute or so (or both).

 I have done a blunder. Can you help me to write the EEPROM writes for this sketch ?
39  Using Arduino / Programming Questions / Re: 'void' does not name type on: August 14, 2011, 12:53:20 am
Mr. Nick
Here is revised sketch Sir.

Code:
//includes
#include <LiquidCrystal.h>
#include <EEPROM.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2); //when LCD is used
//pins
const byte buttonpin1 = 7; // reed switch 1
const byte buttonpin2 = 8; // reed switch 2
const byte buttonpin3 = 9; // reed switch 3
const byte buttonpin4 = 10; // reed switch 4
const byte buttonpin5 = 13; // reed switch 5
byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;
byte state5 = 0;
int Level = 0;

void setup() {
//configure pins   

  pinMode(buttonpin1, INPUT);
  pinMode(buttonpin2, INPUT);
  pinMode(buttonpin3, INPUT);
  pinMode(buttonpin4, INPUT);
  pinMode(buttonpin5, INPUT);
  //setup LCD, when lcd used
  lcd.begin (16,2);
  //intitial message

  lcd.setCursor (0,0);
  lcd.print ("Hello");
 Level = EEPROM.read(0); // read level value from eeprom.

  //Recalling the Level from eeprom you need to fix graph again and states.
  lcd.setCursor (0,1);
  lcd.print ("Last level: ");
  lcd.print (Level);
  delay(5000);
  lcd.clear();

  // Create custom characters to make a ramp
  byte clrChar[8] = { // character needed to clear others
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000,
    B00000
  };
 lcd.createChar(0, clrChar);

byte newChar[8] = { // // black character
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111,
    B11111
  };
 lcd.createChar(1, newChar);
} // end setup()

//This make the display a single function called from inside loop simplifying // the code to fix graph and states.

void display() {
switch (Level) {
  case 1:
    state1 = 0;
    state2 = 1;
    state3 = 1;
    state4 = 1;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(1, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(2, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(3, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(4, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("MIN");// write text next to graph
    break;
  case 2:
    state1 = 0;
    state2 = 0;
    state3 = 1;
    state4 = 1;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(1, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(2, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(3, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(4, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("25%");// write text next to graph
    break;
case3:
    state1 = 0;
    state2 = 0;
    state3 = 0;
    state4 = 1;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(1, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(2, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(3, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(4, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("50%");// write text next to graph
    break;

case4:
    state1 = 0;
    state2 = 0;
    state3 = 0;
    state4 = 0;
    state4 = 1;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(1, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(2, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(3, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(4, 0); // set cursor position.
    lcd.write(0); // write to screen the custom clear character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("75%");// write text next to graph
    break;
case5:
    state1 = 0;
    state2 = 0;
    state3 = 0;
    state4 = 0;
    state4 = 0;
    lcd.setCursor(0, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(1, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(2, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(3, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(4, 0); // set cursor position.
    lcd.write(1); // write to screen the custom graph character.
    lcd.setCursor(6, 0); // set cursor position.
    lcd.print("MAX%”");// write text next to graph
    break;

    //default:
    // if nothing else matches, do the default
    // default is optional
  }
}

void loop(){
display();  // display is called at everyloop and at beginning of it.
  //So at first time will restore the Display and states from the Level stored at eeprom.
 if (digitalRead(buttonpin1) == LOW){ // min
    int state1= digitalRead(buttonpin1);
    Level=1;
    delay(500);  // debounce
  }
 if (digitalRead(buttonpin2) == LOW) // 25%
 {
    state2 = !state2;  // toggle state
    if (state2 >0 ){
      Level = 2;
      if (state2 ==0 ){
        Level =1;
      }
      delay(500);  // debounce
 }
  if (digitalRead(buttonpin3) == LOW) //50%

    {
 state3 = !state3;  // toggle state
  if (state3 >0 ){
   Level = 3;
      }
if (state3 ==0 ){
    Level = 2;
      }
  delay(500);  // debounce
}
 if (digitalRead(buttonpin4) == LOW) // 75%
{
 state4 = !state4;  // toggle state
 if (state4 >0 ){
 Level = 4;
  }
 if (state4 ==0 ){
  Level = 3;
      }
 delay(500);  // debounce
     }
 if (digitalRead(buttonpin5) == LOW) { // max
      state5 = !state5;  // toggle state
      Level = 5;
      // CUT POWER SUPPLY TO PUMP.
      delay(500);  // debounce
     }
if (digitalRead(buttonpin5) == HIGH) {  // max reed off
      state5 = !state5;  // toggle state
      if (state5>1) {
        Level = 4;
      }
delay(500);  // debounce
}
 EEPROM.write(0, Level); // Write to eeprom memory position 0 the Level value.

 // delay(100); // small delay at each loop.
 }
}

40  Using Arduino / Programming Questions / Re: 'void' does not name type on: August 14, 2011, 12:34:53 am
Thanks Mr. Nick
The sketch is compiled with your valuable instructions.
When buttonpin1 is activated it displays the black character and MIN in the lcd. it is OK
but No further displays when the other button pins are activated.
I wish to display
2 black charactors and 25% when buttonpin2 is activated
3 black charactors and 50% when buttonpin3 is activated
4 black charactors and 75% when buttonpin3 is activated
5 black charactors and Max%  when buttonpin5 is activated

What could be the problem?
41  Using Arduino / Programming Questions / 'void' does not name type on: August 13, 2011, 11:02:16 pm
Hi Everyone !
I wish to display a lcd bargraph for liquid level. The code does not compile gives an error 'Void' does not name type.
This is the first problem I am facing, I know there are lot more waiting.....
Kindly help me   smiley-cry


Code:
//includes
#include <LiquidCrystal.h>
#include <EEPROM.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,6,7,8,9) when LCD is used
//pins
const byte buttonpin1 = 2; // reed switch 1
const byte buttonpin2 = 3; // reed switch 2
const byte buttonpin3 = 4; // reed switch 3
const byte buttonpin4 = 5; // reed switch 4
const byte buttonpin5 = 5; // reed switch 5

byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;
byte state5 = 0;
int Level = 0;

void setup() {
//configure pins   
pinMode(buttonpin1, INPUT);
pinMode(buttonpin2, INPUT);
pinMode(buttonpin3, INPUT);
pinMode(buttonpin4, INPUT);
pinMode(buttonpin5, INPUT);
//setup LCD, when lcd used
lcd,begin (16,2);
//intitial message

lcd.SetCursor (0,0);
lcd.print ("Hello");
Level = EEPROM.read(0); // read level value from eeprom.

//Recalling the Level from eeprom
lcd.setCursor (0,1);
lcd.print ("Last level: ");
lcd.print (Level);
delay(5000);
lcd.clear();

// Create custom characters to make a ramp
byte clrChar[8] = { // character needed to clear others
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
lcd.createChar(0, clrChar);
byte newChar[8] = { // // black character
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};

lcd.createChar(1, newChar);
} // end setup()


// the display a single function called from inside loop
Void display() {
 
switch (Level) {
case 1:
state1 = 0;state2 = 1;state3 = 1;state4 = 1;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("MIN");// write text next to graph
break;
case 2:
state1 = 0;state2 = 0;state3 = 1;state4 = 1;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("25%");// write text next to graph
break;
case3:
state1 = 0;state2 = 0;state3 = 0;state4 = 1;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("50%");// write text next to graph
break;

case4:
state1 = 0;state2 = 0;state3 = 0;state4 = 0;state4 = 1;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(0); // write to screen the custom clear character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("75%");// write text next to graph
break;
case5:
state1 = 0;state2 = 0;state3 = 0;state4 = 0;state4 = 0;
lcd.setCursor(0, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(1, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(2, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(3, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(4, 0); // set cursor position.
lcd.write(1); // write to screen the custom graph character.
lcd.setCursor(6, 0); // set cursor position.
lcd.print("MAX%”";// write text next to graph
break;

default:
      // if nothing else matches, do the default
      // default is optional
  }
}

void loop(){

display();  // display is called at everyloop and at beginning of it.
So at first time will restore the Display and states from the Level stored at eeprom.

if (digitalRead(buttonpin1) == LOW){ // min
int state1= digitalRead(buttonpin1);
Level=1;
delay(500);  // debounce
}
 if (digitalRead(buttonpin2) == LOW) // 25%
 {
 state2 = !state2;  // toggle state
 if (state2 >0 ){
Level = 2;
if (state2 ==0 ){
Level =1;
}
delay(500);  // debounce
 }
if (digitalRead(buttonpin3) == LOW) //50%
{
 state3 = !state3;  // toggle state
if (state3 >0 ){
Level = 3;
}
if (state3 ==0 ){
Level = 2;
}
 delay(500);  // debounce
 }
if (digitalRead(buttonpin4) == LOW) // 75%
{
state4 = !state4;  // toggle state
 if (state4 >0 ){
Level = 4;
}
if (state4 ==0 ){
Level = 3;
}
delay(500);  // debounce
 }
if (digitalRead(buttonpin5) == LOW) { // max
state5 = !state5;  // toggle state
Level = 5;
// CUT POWER SUPPLY TO PUMP.
delay(500);  // debounce
 }
if (digitalRead(buttonpin5) == HIGH) {  // max reed off
state5 = !state5;  // toggle state
if (state5>1) {
Level = 4;
}
delay(500);  // debounce
 }
EEPROM.write(0, Level); // Write to eeprom memory position 0 the Level value.
delay(100); // small delay at each loop.
 }

42  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 25, 2011, 11:49:04 am
Thanks Mike

Quote
The setup() function should have a routine in it to read the EEPROM and restore the LED states.

I wrote this routine for setup but no success.

Code:
//write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++)
EEPROM.write(i, 0);
43  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 25, 2011, 12:22:23 am
Hello there !
I am having the  following problem, when I am writing to EEPROM

Power ON all leds are ON. (OK)
When button 1 is pressed led1 goes OFF,       When  Reset  led1 remains OFF. (remembers the state of the button1)
but When button 2 is pressed led2 goes OFF,  When Reset, led2 remains OFF but led1 goes ON (remembers the state of button2 but
looses the state of button2) and so on with other buttons
Note; It remembers only one state of the button at a time.

Problem no. 2 when i insert contiondition  (state1 ==LOW) && (state2 ==LOW)
it  does not behave properly.
Please help me !!
The code I am using is

Code:
#include <EEPROM.h>
const byte buttonpin1 = 2;
const byte buttonpin2 = 3;
const byte buttonpin3 = 4;
const byte buttonpin4 = 5;


const byte ledpin1 = 8;
const byte ledpin2= 9;
const byte ledpin3= 10;
const byte ledpin4= 11;
const byte ledpin6= 12;

byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;

int add = 0;
void setup()
{
   
pinMode(buttonpin1, INPUT);
pinMode(buttonpin2, INPUT);
pinMode(buttonpin3, INPUT);
pinMode(buttonpin4, INPUT);

pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);
pinMode(ledpin4, OUTPUT);
pinMode(ledpin6, OUTPUT);

}
void loop()
{
    if (digitalRead(buttonpin1) == LOW)
 {
        state1 = !state1;  // toggle state
        digitalWrite(ledpin1, state1);
        delay(100);  // debounce
        while (digitalRead(buttonpin1) == LOW) {}
        int state1= digitalRead(buttonpin1);
       
        delay(500);  // debounce
    }
    if (digitalRead(buttonpin2) == LOW)
 {
        state2 = !state2;  // toggle state
        digitalWrite(ledpin2, state2);
        delay(100);  // debounce
        while (digitalRead(buttonpin2) == LOW) {}
         int state2= digitalRead(buttonpin2);
        delay(500);  // debounce
    }
    if (digitalRead(buttonpin3) == LOW)
 {
        state3 = !state3;  // toggle state
        digitalWrite(ledpin3, state3);
        delay(100);  // debounce
        while (digitalRead(buttonpin3) == LOW) {}
         int state3= digitalRead(buttonpin3);
        delay(500);  // debounce
    }
   
    if (digitalRead(buttonpin4) == LOW)
 {
        state4 = !state4;  // toggle state
        digitalWrite(ledpin4, state4);
        delay(100);  // debounce
        while (digitalRead(buttonpin4) == LOW) {}
         int state4= digitalRead(buttonpin4);
        delay(500);  // debounce
    }
   
   if ((state1 ==LOW) && (state2 ==LOW))
  {
  digitalWrite(ledpin6,LOW);
  }
else
  {
  digitalWrite(ledpin6,HIGH);
  }
 
 
  EEPROM.write(0, state1);
  EEPROM.write(0, state2);
  EEPROM.write(0, state3);
  EEPROM.write(0, state4);
 
  add=add+1;
  if( add=512 )
   add=0;

}
44  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 22, 2011, 11:09:17 pm
Thanks Mr. Wildbill

I tried the  following code, which is also working but I think my approach was wrong
Code:
if  ((state1!=1)&&(state2!=1)) {
   digitalWrite(ledpin6,LOW);
} else
{
digitalWrite(ledpin6,LOW);
}
   

I wish to store the status of leds in EEPROM i..e. led1,led2,led3,led4 and led6, In case of power failure, it should show the actual status which was prior to the power failure. I tried the following code but it does not work.Please help me to resolve this issue.


Code:
#include <EEPROM.h>
const byte buttonpin1 = 2;
const byte buttonpin2 = 3;
const byte buttonpin3 = 4;
const byte buttonpin4 = 5;
const byte buttonpin5 = 6;
const byte ledpin1 = 8;
const byte ledpin2= 9;
const byte ledpin3= 10;
const byte ledpin4= 11;
const byte ledpin5 = 12;
const byte ledpin6 = 13;
byte state1 = 0;
byte state2 = 0;
byte state3 = 0;
byte state4 = 0;
byte state5 = 0;
int add = 0;
void setup()
{
   
pinMode(buttonpin1, INPUT);
pinMode(buttonpin2, INPUT);
pinMode(buttonpin3, INPUT);
pinMode(buttonpin4, INPUT);
pinMode(buttonpin5, INPUT);
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);
pinMode(ledpin4, OUTPUT);
pinMode(ledpin5, OUTPUT);
}
void loop()
{
    if (digitalRead(buttonpin1) == LOW)
 {
        state1 = !state1;  // toggle state
        digitalWrite(ledpin1, state1);
        delay(100);  // debounce
        while (digitalRead(buttonpin1) == LOW) {}
        delay(100);  // debounce
    }
    if (digitalRead(buttonpin2) == LOW)
 {
        state2 = !state2;  // toggle state
        digitalWrite(ledpin2, state2);
        delay(100);  // debounce
        while (digitalRead(buttonpin2) == LOW) {}
        delay(100);  // debounce
    }
    if (digitalRead(buttonpin3) == LOW)
 {
        state3 = !state3;  // toggle state
        digitalWrite(ledpin3, state3);
        delay(100);  // debounce
        while (digitalRead(buttonpin3) == LOW) {}
        delay(100);  // debounce
    }
   
    if (digitalRead(buttonpin4) == LOW)
 {
        state4 = !state4;  // toggle state
        digitalWrite(ledpin4, state4);
        delay(100);  // debounce
        while (digitalRead(buttonpin4) == LOW) {}
        delay(100);  // debounce
    }
    if (digitalRead(buttonpin5) == LOW)
 {
        state5 = !state5;  // toggle state
        digitalWrite(ledpin5, state5);
        delay(100);  // debounce
        while (digitalRead(buttonpin5) == LOW) {}
        delay(100);  // debounce
    }
   
    if ((state1 ==LOW) && (state2 ==LOW))
  {
  digitalWrite(ledpin6,LOW);
  }
else
  {
  digitalWrite(ledpin6,HIGH);
  }
 
  EEPROM.write(0, state1);
  EEPROM.write(0, state2);
  EEPROM.write(0, state3);
  EEPROM.write(0, state4);
  EEPROM.write(0, state5);
   
}
45  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 20, 2011, 10:41:56 pm


Trying to switch ON led6  when the state of button 1 & 2 is LOW
but it does not work. Please guide me What is the correct way to make it working ?




Code:
if ((state1 =!state1) && (state2 =!state2))
    {
    digitalWrite(ledpin6,LOW);
    }else{
    digitalWrite(ledpin6,HIGH);
    {
Pages: 1 2 [3] 4