Show Posts
Pages: 1 2 3 [4]
46  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 10, 2011, 12:56:28 am
Thanks all for enlightening me. The sketch is working OK
How to implement logical operators  ie. AND  OR  in above mentioned code ?
The state of five buttons & leds  are being monitored, when the button is pressed coressponding led comes ON.
Suppose we want ledpin6 to be ON when ledpin3  and ledpin4 comes ON
i.e. digitalRead(ledpin3==LOW && ledpin4==LOW); digitalWrite(ledpin6==LOW)






47  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 08, 2011, 08:34:34 pm
Thanks Mike.
Intially when the board is powered or reset, leds does not work with single push, it required two pushes
to make it working, afterwards it works with single push. What could be the problem with this code ?

48  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 07, 2011, 11:49:49 pm

Trying to change the above mentioned program to Arrays but it gives the following error and does not compile.
Void loop () {
A-function definition is not allowed here before "{" token
Please help to resove this issue.
Code:
const byte buttons[]={2,3,4,5,6};
const byte leds[] = {8,9,10,11,12};
byte state[]={1,2,3,4,5};

void setup()
{
byte i;
for (i = 0; i < 5; i = i + 1) {

pinMode(buttons[i], INPUT);
pinMode(leds[i],OUTPUT);
}
void loop(){
 byte i;
for (i = 0; i < 5; i = i + 1) {
 
{
    if (digitalRead(buttons[i]) == LOW)
 {
        state[i] = !state[i]  // toggle state
        digitalWrite(leds[i], state[i]);
        delay(10);  // debounce
        while (digitalRead(buttons[i]) == LOW) {}
        delay(10);  // debounce
    }
   
    }
}
49  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 04, 2011, 11:22:42 pm

Thanks Mr. Wildbill.
I tested the code for single led. It is working OK.
You are right that I am sharing the state variables among the 5 leds, this is the main cause of the malfunction.
How do I share the state variables among 5 leds in this particular sketch to make it working ?
50  Using Arduino / LEDs and Multiplexing / Re: Momentary button as ON/OFF Switch on: June 04, 2011, 02:08:27 am

Switches are connected                                                     

                        o +5V                               
                        |                                       
                        |                                                                               
                        /                                   
                        \ 10K
                        /
                        |    100 Ohm
                        o----/\/\/----o To pin   
                        |
                        o
                        o  Switch
                        |
                        GND
                                           
LEDs are connected with pullup resistor of 560 Ohms
51  Using Arduino / LEDs and Multiplexing / Momentary button as ON/OFF Switch on: June 03, 2011, 11:09:14 pm
This code does not work, what could be the reason ?

Code:
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;
byte state = 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) == HIGH)
 {
        state = !state;  // toggle state
        digitalWrite(ledpin1, state);
        delay(10);  // debounce
        while (digitalRead(buttonpin1) == HIGH) {}
        delay(10);  // debounce
    }
    if (digitalRead(buttonpin2) == HIGH)
 {
        state = !state;  // toggle state
        digitalWrite(ledpin2, state);
        delay(10);  // debounce
        while (digitalRead(buttonpin2) == HIGH) {}
        delay(10);  // debounce
    }
    if (digitalRead(buttonpin3) == HIGH)
 {
        state = !state;  // toggle state
        digitalWrite(ledpin3, state);
        delay(10);  // debounce
        while (digitalRead(buttonpin3) == HIGH) {}
        delay(10);  // debounce
    }
    if (digitalRead(buttonpin4) == HIGH)
 {
        state = !state;  // toggle state
        digitalWrite(ledpin4, state);
        delay(10);  // debounce
        while (digitalRead(buttonpin4) == HIGH) {}
        delay(10);  // debounce
    }
    if (digitalRead(buttonpin5) == HIGH)
 {
        state = !state;  // toggle state
        digitalWrite(ledpin5, state);
        delay(10);  // debounce
        while (digitalRead(buttonpin5) == HIGH) {}
        delay(10);  // debounce
    }
}
52  Using Arduino / Programming Questions / Re: Digital Multiple Voltage Power Supply on: May 19, 2011, 11:18:52 am
Karnika
I am not sure but you can  TRY THIS
From your Schematic it is evident  that you are  using two switches S1 and S2 for  (Increasing & Decreasing the output Voltage) 

 If S1 (-) is pressed                           
   If its at its lowest value and DOWN is pressed, roll over to the highest value
   else
If its not at its lowest value
outPin >>= 1;
Lower it by a power of 2 (bit shift it to the right by 1
Set the output port/pin
(this will make its output high on the pin that corresponds to outPin's value)
      
If S2 (+) was pressed
 If its at its highest value and UP is pressed, roll over to the lowest value
else
 If its not at its highest value
outPin <<= 1;
lower it by a power of 2 (bit shift it to the right by 1)
Set the output port/pin to  outPin value (this will make it output high on the pin that corresponds to outPin's value)
return 0;
Best of Luck

53  Forum 2005-2010 (read only) / Syntax & Programs / Re: Water Level Indicator on: November 03, 2010, 08:48:47 am
Sir,
I did not understand the Gadget Shield:,I am confused  :(can you give me the code for EEPROM for these four levels so that I get an idea how  to write and read  the value in the EEPROM and my EEPROM remain safe. I am using ATmega 328 and curious to use the EEPROM and Flash memory in my future projects.








54  Forum 2005-2010 (read only) / Syntax & Programs / Re: Water Level Indicator on: November 01, 2010, 10:45:36 pm
Sir,
Please check up this code:

#include <EEPROM.h>
//Tank Level Display
int Level1 = 4;
int Level2 = 5;
int Level3 = 6;
int Level4 = 7;


int Level1State=0;
int Level2State=0;
int Level3State=0;
int Level4State=0;


int Sensor =0;
float SensorValue=0;
int add = 0; //address of EEPROM byte we will be writing to

void setup() {
//  Tank  Level Display
pinMode(Level1, OUTPUT);
pinMode(Level2, OUTPUT);
pinMode(Level3, OUTPUT);
pinMode(Level4, OUTPUT);

// Control



void loop () {
SensorValue=analogRead(Sensor);
SensorValue /=1024;
SensorValue *=5;



// Sump Tank Level Display
{
if (SensorValue < 1.4)     doOutput(0);
EEPROM.write(1,value );
else if (SensorValue < 2.1) doOutput(1);
EEPROM.write(2,value );
else if (SensorValue < 2.smiley-cool doOutput(3);
EEPROM.write(3,value );
else if (SensorValue < 3.0) doOutput(7);
EEPROM.write(4,value );
else doOutp
}

void doOutput(unsigned char val) {
digitalWrite(Level1, (val & 0x8) ? HIGH : LOW);
digitalWrite(Level2, (val & 0x4) ? HIGH : LOW);
digitalWrite(Level3, (val & 0x2) ? HIGH : LOW);
digitalWrite(Level4, (val & 0x1) ? HIGH : LOW);
}


55  Forum 2005-2010 (read only) / Syntax & Programs / Re: Water Level Indicator on: November 01, 2010, 11:11:35 am

Sir,
Can you explain it in a simple way about this coding .
Sorry to ask this stupid  question.
56  Forum 2005-2010 (read only) / Syntax & Programs / Water Level Indicator on: October 31, 2010, 08:36:53 pm
I am a Marine Engineer and electronics hobbyist  I was very much impressed by the arduino community who are doing a fantastic job to encourage the students, professional and hobbyist. . I have gone through various arduino programs/posts and wrote this first program. Please help me to resolve the following issues and point out the mistakes in my program

The Sump Tank shall be fitted with  a series of resistances & reed switches inside a
plastic tube with a magnetic float out side the stem. When the water level rises/falls the float will also rise and fall and  the reed switches will make/ break. Thus it will act as a voltage divider.

Issues: 1.  When the magnetic float is between Level 1 & 2, the reed switch breaks
and hence no display of the level. How to hold/latch  the value of the level
2. If in case of power failure it should remember the previous level.




//Tank Level Display
int Level1 = 4;
int Level2 = 5;
int Level3 = 6;
int Level4 = 7;


int Level1State=0;
int Level2State=0;
int Level3State=0;
int Level4State=0;


int Sensor =0;
float SensorValue=0;

void setup() {
//  Tank  Level Display
pinMode(Level1, OUTPUT);
pinMode(Level2, OUTPUT);
pinMode(Level3, OUTPUT);
pinMode(Level4, OUTPUT);

// Control
pinMode (pumpRelay, OUTPUT);


void loop () {
SensorValue=analogRead(Sensor);
SensorValue /=1024;
SensorValue *=5;



// Sump Tank Level Display

if(SensorValue >=3.0)
{
digitalWrite(Level1,HIGH);
delay (50);
} else
{
 digitalWrite(Level1,LOW);
delay (50);
}
 
 if (SensorValue >=2.smiley-cool
{
digitalWrite(Level2,HIGH);
delay (50);
} else
{
 digitalWrite(Level2,LOW);
delay (50);
}

if (SensorValue >=2.10)
{
digitalWrite(Level3,HIGH);
delay (50);
} else
{
 digitalWrite(Level3,LOW);
delay (50);
}

if (SensorValue >=1.4)
{
digitalWrite(Level4,HIGH);
delay (50);
} else
{
 digitalWrite(Level4,LOW);
delay (50);
{
{
 digitalWrite(otkLevel4,LOW);
delay (50);
}





Pages: 1 2 3 [4]