Go Down

Topic: Need Help With RandomSeed and Number Count (Read 151 times) previous topic - next topic

jlfalin

Hi,  I am new to Arduino.  I am currently trying to make a controller to control a variable speed fish aquarium pump.  During playing with the coding I ran into a small problem.  I am trying to have a randomseed generator run to produce random numbers.  I am also trying to run a push button counter that will allow me to switch between the different modes that I want to run.  Can these two things be done at the same time on an Uno.  Here is my code.  The pushbuttoncounter was working great until I added the  randomSeed(analogRead(1)); statement now nothing works and I cannot select between my different options.  Any input would be greatly appreciated.

Code: [Select]
const int LED = 13;
const int BUTTON = 7;
const int TxPin = 6;
long RandomIN;
long RandomOut;

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial (255, TxPin);


int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup(){
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);
  pinMode(TxPin, OUTPUT);
  randomSeed(analogRead(1));
  Serial.begin(9600);
}

void loop(){
    buttonState = digitalRead(BUTTON);
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH){
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    }
    else {
      Serial.println("off");
    }
  }
   
    lastButtonState = buttonState;
   
if (buttonPushCounter == 0) {     
    mySerial.begin(9600);
    delay(100);
    mySerial.write(12);
    mySerial.write(17);
    delay(5);
    mySerial.print("Ramp Mode");
    mySerial.write(13);
}

if (buttonPushCounter == 1) {
   mySerial.begin(9600);
    delay(100);
    mySerial.write(12);
    mySerial.write(17);
    delay(5);
    mySerial.print("Wave Mode");
    mySerial.write(13);
   }

if (buttonPushCounter ==2) {
  mySerial.begin(9600);
  delay(100);
  mySerial.write(12);
  mySerial.write(17);
  mySerial.print("Reef Crest");
  mySerial.write(13);
  }
if (buttonPushCounter ==3){
  buttonPushCounter =0;}
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy