Show Posts
Pages: [1] 2 3 ... 39
1  Using Arduino / Programming Questions / Re: Sketch won't exit from while statement on: June 26, 2014, 06:51:48 am
Thanks all. I have got it working now,

Many thanks to ecojack, I was not aware of that. Thank you for sharing!

One other thing I would like to do is to execute a line of code ONLY once, when the while statement becomes untrue - is there a simple way to do this?
2  Using Arduino / Programming Questions / Re: Sketch won't exit from while statement on: June 24, 2014, 08:26:07 am
I think I follow, thanks for the help.

So I'm declaring double t1 again inside the while loop and I don't need too?

Thanks again
3  Using Arduino / Programming Questions / Sketch won't exit from while statement on: June 24, 2014, 05:54:53 am
Hi all. I'm confused, I am taking a temperature reading, and when it goes about a certain value the sketch enters a while loop (while (t1 > 65),  which switches power off until it cools below the value.

The sketch enters the while loop but won't exit it - I'm confused because I can see the value dropping below the set point on serial  monitor and on the LCD whilst in the while loop but like I said, it never seems to become untrue?

Thanks in advance!

Code:
#include <LCD5110_Basic.h>
#include <math.h>

//Thermistor measurements and averaging
#define NUMSAMPLES 16 // Number of analog samples to take
float averageTemp = 0;         //place to store average reading
double convert(double RawADC)
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  return Temp;
}
#define t1Pin A3  // Input pin for the thermistor 1
float average1 = 0;                     //input1

int val = 3;

LCD5110 myGLCD(8,9,10,11,12);

extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];

int backLight = 6;
int UV = 5;


// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int enterState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

long runTime = 0;
long startMillis = 0;
int remainingB = 0;
long remaining = 0;

bool running = true;

int selectButton = 2;
int enterButton = 3;

void setup()
{
  Serial.begin(9600);
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  pinMode(UV, OUTPUT);
  pinMode(backLight, OUTPUT);
  analogWrite(backLight, 255);

  //Buttons
  pinMode(enterButton, INPUT);
  pinMode(selectButton, INPUT);
  digitalWrite(enterButton, HIGH);
  digitalWrite(selectButton, HIGH);
}

void loop()
{

  checkButton();

  while (buttonPushCounter == 0)    //Display amount menu
  {
    runTime = 30;
    //Serial.println(runTime);
    //myGLCD.clrScr();
    myGLCD.print("Select:", LEFT, 0);
    myGLCD.print("30 seconds", CENTER, 16);
    myGLCD.print("Next     Start", CENTER, 40);
    enter ();
    checkButton();
    //delay (5000);
    getTemp();  
  }


  while (buttonPushCounter == 1)    //Display amount menu
  {
    runTime = 60;
    //Serial.println(runTime);
    //myGLCD.clrScr();
    myGLCD.print("Select:", LEFT, 0);
    myGLCD.print("60 seconds", CENTER, 16);
    myGLCD.print("Next     Start", CENTER, 40);
    enter ();
    checkButton();
    //delay (5000);
    getTemp();
  }

  while (buttonPushCounter == 2)    //Display amount menu
  {
    runTime = 120;

    //myGLCD.clrScr();
    myGLCD.print("Select:", LEFT, 0);
    myGLCD.print("120 seconds", CENTER, 16);
    myGLCD.print("Next     Start", CENTER, 40);
    enter ();
    checkButton();
    //delay (5000);
    getTemp();
  }

  while (buttonPushCounter == 3)    //Display amount menu
  {
    runTime = 180;

    //myGLCD.clrScr();
    myGLCD.print("Select:", LEFT, 0);
    myGLCD.print("180 seconds", CENTER, 16);
    myGLCD.print("Next     Start", CENTER, 40);
    enter ();
    checkButton();
    //delay (5000);
    getTemp();
  }

} //end of loop


void getTemp()
{
  // Thermistor measurement and averaging
  uint8_t i;
  for (i=0; i< NUMSAMPLES; i++)            
  {
    val = analogRead(3);
    //Serial.println(val);
    val = map(val, 0, 1023, 1023, 0);

    average1 += val;
    delay(10);
  }
  average1 /= NUMSAMPLES;


  double t1 = convert(average1);
Serial.println(t1);

  myGLCD.printNumI(t1, 60, 0);
  myGLCD.print("~c", 72, 0);


  while (t1 > 65)
  {

    analogWrite(UV, 0);
    // Thermistor measurement and averaging
    uint8_t i;
    for (i=0; i< NUMSAMPLES; i++)            
    {
      val = analogRead(3);
      //Serial.println(val);
      val = map(val, 0, 1023, 1023, 0);

      average1 += val;
      delay(10);
    }
    average1 /= NUMSAMPLES;


    double t1 = convert(average1);
    Serial.println(t1);
    myGLCD.clrScr();
    myGLCD.printNumI(t1, 60, 0);
    myGLCD.print("~c", 72, 0);
    myGLCD.print("Over Temp!!", CENTER, 16);
  }  
}



void enter ()
{
  enterState = digitalRead(enterButton);
  //Serial.println(enterState);
  if (enterState == 0)
  {
    running = true;
    delay(500);
    myGLCD.clrScr();

    startMillis = millis();
    if (running == true)
    {

      runTime = (runTime * 1000);
      Serial.println(runTime);
      remaining = ((startMillis + runTime) - millis());

      //while (millis() <= (startMillis + runTime))
      while (remaining > 0)
      {
        myGLCD.clrRow(2);
        myGLCD.clrRow(3);
        myGLCD.clrRow(4);

        analogWrite(UV, 255);
        remaining = ((startMillis + runTime) - millis());
        //Serial.println(millis());

        myGLCD.print("Running:", LEFT, 0);
        //remainingB = remaining;
        //myGLCD.printNumI((remainingB / 1000), CENTER, 16);
        myGLCD.setFont(BigNumbers);
        myGLCD.printNumI((remaining / 1000), CENTER, 16);
        myGLCD.setFont(SmallFont);
        getTemp();
        myGLCD.print("Stop", LEFT, 40);
        checkButton();
        running = false;
        delay(50);
      }
      analogWrite(UV, 0);
      myGLCD.clrScr();
      myGLCD.invert(true);
      myGLCD.print("Finished", CENTER, 16);
      delay (3000);
      myGLCD.invert(false);
      myGLCD.clrScr();
      buttonPushCounter = 0;
    }
  }
}



void checkButton()
{
  // read the pushbutton input pin:
  buttonState = digitalRead(selectButton);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {

    running = false;
    remaining = 0;

    // if the state has changed, increment the counter
    if (buttonState == LOW) {
      //remaining = 0;

      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
      myGLCD.clrScr(); //clear lcd in between screens
    }
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;


  if(buttonPushCounter == 4)
    buttonPushCounter = 0;

} //end of sub routine

4  Using Arduino / LEDs and Multiplexing / Re: 74HC595 causes LED'S TO flash when arduino starts up on: June 12, 2014, 04:53:26 am
thanks Paul I will give it  go when i get some time!

Which is pin 10 on the shift regsisters? I'm using them in non-spi mode as I'm using them with a Ethernet shield.
5  Using Arduino / LEDs and Multiplexing / Re: 74HC595 causes LED'S TO flash when arduino starts up on: June 12, 2014, 04:22:17 am
thanks Paul I will give it  go when i get some time!

Which is pin 10 on the shift regsisters? I'm using them in non-spi mode as I'm using them with a Ethernet shield.
6  Using Arduino / LEDs and Multiplexing / Re: 74HC595 causes LED'S TO flash when arduino starts up on: June 10, 2014, 06:04:34 am
Hi Jimbo, I will give that a go then thanks! -all 3 shift register pins?

Thought it would be a hardware thing but if its only software that would be great
7  Using Arduino / LEDs and Multiplexing / 74HC595 causes LED'S TO flash when arduino starts up on: June 10, 2014, 05:30:47 am
Hi all,

Just a niggle with my project - when I apply power to my arduino all the leds that I'm driving (via mosfets) from a few 74HC595'S blink for a fraction of a second - is there a hardware mod that I can do to eradicate this?

thanks!
8  Community / Exhibition / Gallery / Re: Lib for manipulating cascaded 595 shift registers on: June 09, 2014, 08:51:05 am
thanks for sharing, looks very useful smiley
9  Community / Exhibition / Gallery / Re: [ASTROPHOTO] Autoguiding using an old webcam and an arduino on: June 09, 2014, 08:49:01 am
amazing! looks like epic work, have you got any images to share to show the results?
10  Community / Exhibition / Gallery / Re: TLC 5940 4x4x4 RGB LED cube on: June 03, 2014, 08:46:58 am
cool thanks for sharing
11  Topics / Science and Measurement / Re: Best logging site to use on: June 02, 2014, 06:59:53 am
Thanks for the replies. I can't find my old code. I a play over the weekend and got Xively working but not very impressed really, seems quite limited what it can do. Might have to check out Grovestreams
12  Topics / Science and Measurement / Re: Best logging site to use on: May 30, 2014, 04:03:27 am
Thanks Nick. It looks a lot more complicated than I remember - I will see if I can work it out though smiley
13  Topics / Science and Measurement / Best logging site to use on: May 29, 2014, 08:09:22 am
Hi all, I want to send data from a arduino to the cloud and be able to view on a graph. It has been a few years since I did anything like this, so long in fact that I cannot remember the name of the service that I used before, but I think I remember hearing that it dropped off the map anyhow.

What are people using these days?
14  Using Arduino / Programming Questions / checkString function causing issues on: February 12, 2014, 08:38:00 pm
Hi all. I am trying to read a string from a http request. It was working fine until I went to add more functions - one of those strings is called 'mode10' however, this string gets picked up when i check for a string called 'mode1'. I tried with other numbers and nothing >10 will work.

What is going on here? I thought it would check for the exact string including all characters but I guess as soon as it has a match it accepts it?

I can of course post the whole code if necessary but its rather long and badly structured at the moment

Code:
void checkString(){
  if(readString.indexOf("?mode1") >0)
  {
    if (debug == true)
      Serial.println("mode1");
    //starsTrue = false;
    mode = 1;
    mode1();
15  Using Arduino / Project Guidance / Re: DS1307 problem and DS3231 on: February 06, 2014, 11:02:10 am
I have the same problem with a ds1307 - the time keeping is useless! I wonder if I should try and change the xtal?

Does anyone know if the https://github.com/adafruit/RTClib will work with a DS3231?

Thanks
Pages: [1] 2 3 ... 39