Show Posts
Pages: 1 ... 20 21 [22] 23 24 ... 252
316  Using Arduino / Programming Questions / Re: Serial.read on: July 29, 2014, 09:14:53 pm
It does kinda work if you send "YesnoYes"
I've been playing around with it and for multiple strings, its not very responsive. but I never said it was the best way to solve the OP's issue.

Also PeterH made my first option already.
317  Using Arduino / Programming Questions / Re: Serial.read on: July 29, 2014, 07:49:52 pm
A little simpler:

Code:
void setup()
{
  Serial.begin(115200);
}

void loop()
{
 if(Serial.available() > 2) // checks for at least 3 chars are entered
 {
  if(Serial.find("Yes"))
    Serial.println("Found it");
  else
    Serial.println("Not found");
 }
}
318  Using Arduino / Project Guidance / Re: Help with serial println please? on: July 29, 2014, 07:18:38 pm
Edit: smiley-lol
char dataline1[30]; // global variable arrays
.
.
.
sprintf(dataline1, "sensor1 = %d  sensor2 = %d  sensor3 = %d", sensorA, sensorB, sensorC); // in loop of function
.
.
.
Serial.println(dataline1); // somewhere else in the loop
319  Using Arduino / Project Guidance / Re: Arduino unresponsive after a long time on: July 29, 2014, 07:05:47 pm
I changed a few things with this part.
Quote
if(Serial.available()) // <- Made just IF, not ELSE IF
  {
    char inputChar;
    inputChar = Serial.read();
    //    Serial.println(inputChar);
    Serial.read();
    if(inputChar == 'o')//o for on <- Made them actual chars
    {
      on = 1;
      int randNum = random(3);
      switch(randNum)
      {//random clock colors on startup
      case 0:
        mode =20;
        break;
      case 1:
        mode = 21;
        break;
      case 2:
        mode = 22;
        break;  
      }
      digitalWrite(7,LOW);
    }
    else if(inputChar == 'O')//O for off <- same here
    {
      digitalWrite(7,HIGH);
      on = 0;
      mode =123;
      resetTime = millis();
    }
    if(on ==1)
    {
      Serial.println("I am Here"); // <- added this to see where the code was at
      if(inputChar==104)//h for help
      {
        startup();
      }
      else if (inputChar ==108)//l for list of modes
      {
        modeList();
      }
      else if (inputChar ==112)//p for pretty colors
      {
        colors();
      }
      else
      {
        Serial.println("Enter Parameters");
        while(!Serial.available())
        { }
        switch(inputChar)
        {
        case 109://m for mode
          mode = Serial.parseInt();
          //        Serial.println(mode);
          break;
          
        case 98://b for background
          backR=brightnessLimit(Serial.parseInt());
          backG=brightnessLimit(Serial.parseInt());
          backB=brightnessLimit(Serial.parseInt());
          //        Serial.print((backR));
          //        Serial.print(F("."));
          //        Serial.print((backG));
          //        Serial.print(F("."));
          //        Serial.println((backB));
          break;

        case 99://c for color
          globalR=brightnessLimit(Serial.parseInt());
          globalG=brightnessLimit(Serial.parseInt());
          globalB=brightnessLimit(Serial.parseInt());
          //        Serial.print((globalR));
          //        Serial.print(F("."));
          //        Serial.print((globalG));
          //        Serial.print(F("."));
          //        Serial.println((globalB));
          break;
          
        case 100://d for delay
          myDelay = Serial.parseInt();
          //        Serial.println(myDelay);
          break;
          
        case 115://s for set display message
          currentMessage = Serial.parseInt();
          //        Serial.println(myDelay);
          break;
          
        case 105://i for intensity of light
          maxBrightness = Serial.parseInt();
          //        Serial.println(maxBrightness);
          break;
          
        case 122://z for background brightness
          backGroundBrightness = Serial.parseInt();
          break;

          default: break; //<- Add a default case
        }
        Serial.read();
      }
    }
320  Using Arduino / Project Guidance / Re: Arduino unresponsive after a long time on: July 29, 2014, 04:29:01 pm
There might be a memory leak somewhere, but I'm not certain until I can get home and do some tests.
321  Using Arduino / Project Guidance / Re: Bluetooth with multiple slaves on: July 29, 2014, 04:20:34 pm
What about something like this, its not a module though.
https://www.kickstarter.com/projects/458038473/jambadoo-a-bluetooth-receiver-that-can-connect-to
322  Using Arduino / Programming Questions / Re: Readling Serial communication from RF links on: July 29, 2014, 04:07:00 pm
Yea, add an else statement to turn them back LOW when nothing is pressed or comes in.

Example:
if (msg == 'g' || c == 'g')
{
      digitalWrite(greenLED, HIGH);
}
else
     digitalWrite(greenLED, LOW);
323  Using Arduino / Project Guidance / Re: Bluetooth with multiple slaves on: July 29, 2014, 03:59:11 pm
Quote
do u have a example of a Bluetooth module that can handle multiple slaves.
I don't, but have you tried doing a search?
324  Using Arduino / Project Guidance / Re: Arduino unresponsive after a long time on: July 29, 2014, 03:57:14 pm
Do you ever see "Enter Parameters" ?
325  Using Arduino / Project Guidance / Re: Arduino unresponsive after a long time on: July 29, 2014, 03:39:34 pm
We have to be able to read what were looking at.

A lot of this is very eye straining,

Some code here
Some code here
Some code here
Some code here
Some code here
Some code here
Some code here
Some code here
Some code here
326  Using Arduino / Programming Questions / Re: Multiple rgb led and switch change on: July 29, 2014, 03:34:12 pm
I might have the operator in this backwards.
Quote
if (millis() - lasttime < DEBOUNCE)
  {
    lasttime = millis();
    return;
  }
  else
    lasttime = millis();

I can't test your code until I get home at 6pm.
327  Using Arduino / Programming Questions / Re: Readling Serial communication from RF links on: July 29, 2014, 03:22:59 pm
Quote
But when pressing the buttons they won't?
Thats because your LEDs are only looking at the serial monitor.

Replace
Quote
if (Serial.available() > 0)
{
    msg = Serial.read();
    if (msg == 'g'){
    digitalWrite(greenLED, HIGH);
    }
    if (msg =='r'){
      digitalWrite(redLED, HIGH);
    }
    if (msg == 'y'){
      digitalWrite(yellowLED, HIGH);
    }
    if (msg == 'G'){
      digitalWrite(greenLED2, HIGH);
    }
  }

with this
Code:

if (Serial.available() > 0)
{
    msg = Serial.read();
}

if (msg == 'g' || c == 'g')
{
      digitalWrite(greenLED, HIGH);
}

if (msg =='r' || c == 'r'){
      digitalWrite(redLED, HIGH);
}

if (msg == 'y' || c == 'y')
{
      digitalWrite(yellowLED, HIGH);
}

if (msg == 'G' || c == 'G')
{
      digitalWrite(greenLED2, HIGH);
}

328  Using Arduino / Project Guidance / Re: Arduino unresponsive after a long time on: July 29, 2014, 03:15:34 pm
O_O,

Length is not really an issue, but no spacing, why...?
This will take some time to go through.
329  Using Arduino / Programming Questions / Re: Multiple rgb led and switch change on: July 29, 2014, 03:08:16 pm
Try this code, If there is no difference, please post pictures or a video.

Code:
#define DEBOUNCE 10

// output pins
int inMin = 2;
int inMax = 49;

//input pins
byte button[16]= {
  A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};

#define NUMBUTTONS sizeof(button)

boolean buttonpressed[NUMBUTTONS], pressed[NUMBUTTONS];
boolean previousstate[NUMBUTTONS];
boolean currentstate[NUMBUTTONS];

boolean state[16];

boolean lastState[16];

long previousMillis[48];

long interval[48] = {
  500, 600, 550, 500, 600, 550, 500, 600, 550};

long time[48];
long lasttime;

void setup()
{
  Serial.begin(9600); 

  for(int i=inMin; i <= inMax; i++)
  {
    pinMode(i, OUTPUT);
  }   

  for(i = 0; i< 16; i++)
  {
    pinMode(button[i], INPUT);
    buttonpressed[i] = 0;
    lastState[i] = LOW;
    state[i] = LOW;
  }

  for(int i=0; i<48; i++)
  {
    previousMillis[i] = 0;
    time[i] = millis();
  }
}

void check_switches()
{
  byte index;

  if (millis() - lasttime < DEBOUNCE)
  {
    lasttime = millis();
    return;
  }
  else
    lasttime = millis();

  for (index = 0; index < NUMBUTTONS; index++)
  {
    buttonpressed[index] = 0;

    currentstate[index] = digitalRead(button[index]);
    if(currentstate[index] != previousstate[index])
    {
      previousstate[index] = currentstate[index];
      if(currentstate[index] == HIGH)
      {
        buttonpressed[index] = 1;
      }
    }
  }
}


void loop()
{
  check_switches();

  if (lastState[0] != buttonpressed[0])  // check for state change
  {
    if(buttonpressed[0]) // if button state is HIGH, then do something
    {
      state[0]++;
      if (state[0] > 1)
      {
        state[0] = 0;
      }
    }
    lastState[0] = buttonpressed[0]; // update lastState
  }
  if (state[0] == 0)
  {
    square1();
  }

  else if (state[0] == 1)
  {
    square1solid();
  }

  if (lastState[1] != buttonpressed[1])
  {
    if(buttonpressed[1])
    {
      state[1]++;
      if (state[1] > 1)
      {
        state[1] = 0;
      }
    }
    lastState[1] = buttonpressed[1];
  }
  if (state[1] == 0)
  {
    square2();
  }

  else if (state[1] == 1)
  {
    square2solid();
  }

  if (lastState[2] != buttonpressed[2])  // check for state change
  {
    if(buttonpressed[2]) // if button state is HIGH, then do something
    {
      state[2]++;
      if (state[2] > 1)
      {
        state[2] = 0;
      }
    }
    lastState[2] = buttonpressed[2]; // update lastState
  }
  if (state[2] == 0)
  {
    square3();
  }

  else if (state[2] == 1)
  {
    square3solid();
  }
}




/////////////////////////////////Square 1///////////////////////////////////

void square1solid()
{
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
}

void square1()
{
  unsigned long currentMillis1 = millis();
  if (currentMillis1 - time[0] > interval[0])
  {
    time[0] = currentMillis1;
    lastState[0] = !lastState[0];
    digitalWrite(2, lastState[0]);
  }

  unsigned long currentMillis2 = millis();
  if (currentMillis2 - time[1] > interval[1])
  {
    time[1] = currentMillis2;
    lastState[1] = !lastState[1];
    digitalWrite(3, lastState[1]);
  }

  unsigned long currentMillis3 = millis();
  if (currentMillis3 - time[2] > interval[2])
  {
    time[2] = currentMillis3;
    lastState[2] = !lastState[2];
    digitalWrite(4, lastState[2]);
  }
}

/////////////////////////Square 2////////////////////////////////
void square2solid()
{
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}


void square2()
{
  unsigned long currentMillis4 = millis();
  if (currentMillis4 - time[3] > interval[3])
  {
    time[3] = currentMillis4;
    lastState[3] = !lastState[3];
    digitalWrite(5, lastState[3]);
  }

  unsigned long currentMillis5 = millis();

  if (currentMillis5 - time[4] > interval[4])
  {
    time[4] = currentMillis5;
    lastState[4] = !lastState[4];
    digitalWrite(6, lastState[4]);
  }

  unsigned long currentMillis6 = millis();

  if (currentMillis6 - time[5] > interval[5])
  {
    time[5] = currentMillis6;
    lastState[5] = !lastState[5];
    digitalWrite(7, lastState[5]);
  }
}
/////////////////////////Square 3////////////////////////////////
void square3solid()
{
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
}

void square3()
{
  unsigned long currentMillis7 = millis();
  if (currentMillis7 - time[6] > interval[6])
  {
    time[6] = currentMillis7;
    lastState[6] = !lastState[6];
    digitalWrite(8, lastState[6]);
  }

  unsigned long currentMillis8 = millis();

  if (currentMillis8 - time[7] > interval[7])
  {
    time[7] = currentMillis8;
    lastState[7] = !lastState[7];
    digitalWrite(9, lastState[7]);
  }

  unsigned long currentMillis9 = millis();

  if (currentMillis9 - time[8] > interval[8])
  {
    time[8] = currentMillis9;
    lastState[8] = !lastState[8];
    digitalWrite(10, lastState[8]);
  }
}
330  Using Arduino / Programming Questions / Re: Serial.read on: July 29, 2014, 02:32:03 pm
There is a couple ways you can do this but first I need to clarify, Yes is not a single char so 'Yes' wont work, it's a char string(an array of chars).

1) Read in each char and store them in an array(I think it need to be NULL terminated) then use strcmp() to see if what you sent is a match to what you're looking for.

2) Use Serial.find() to go through the serial buffer and see if the chars 'Y','e','s' are found together.

Pages: 1 ... 20 21 [22] 23 24 ... 252