Show Posts
Pages: [1] 2 3 ... 116
1  Using Arduino / Programming Questions / Re: if else or switch case? on: April 22, 2014, 09:53:13 pm
Not sure I'd that would work for me,  for my case there's a. Good chance there won't be an errors except capitalizion,  wrong input would be discarded,  and I'm not using it directly from the stream to ensure I have the whole command string before processing it,  I'll just have a default case that will send a string that says command not recognizd,
I guess to get the best result I'll have to make too versions of the code or atleast a test code and compare the overall response time to know for sure which of the two methods is faster
2  Using Arduino / Programming Questions / Re: if else or switch case? on: April 20, 2014, 11:19:16 pm
still not sure if switch case is better or not than if/else but just starting with the crazy compare statements how does this look? seem like itll work?

Code:
if((btbuffer[3] == 'C') && (btbuffer[4] == 'H') && (btbuffer[5] == '6') ){//original method example
            analogWrite(ch6, numberinput);
            EEPROM.write(60,numberinput);
    } else
    if(! strcmp(commandstring, "ch5")){ // new attempt simple example
           analogWrite(ch5, numberinput);
          EEPROM.write(50,numberinput);
    } else
//my command string is 5 char long(for now) with the null terminator so will comparing to  a shorter string work?

 if(! strcmp(commandstring, "RED")){ //comparing to three character string
//change outputs for red
} else
if(! strcmp(commandstring,"GREEN")){//comapring to full length string
//change outputs for green
}




3  Using Arduino / Programming Questions / Re: if else or switch case? on: April 20, 2014, 04:49:32 pm
Not really numerical,  the re  is a part of the array that is numerical but I extract that and use it separately , and about the strings and Strings,  would those commands mentioned earlier work for either or just one?
4  Using Arduino / Programming Questions / Re: if else or switch case? on: April 20, 2014, 02:09:27 pm
Thats actually the first time I've ever used gotos , just a quick fix to a not so thought out program flow,  I'm gonna definetly use a more thought out flow second time around, 
I usually try and stay away from strings,  when I was Learning someone told me they are ram intensive, Is that true? Definitely would be alot simpler to have defined strings, extract the command string out of the array,  and compare,  but if using strings will slow things down I'd rather type more and have that complicated to read if statement,
5  Using Arduino / Programming Questions / Re: if else or switch case? on: April 19, 2014, 07:49:22 pm
Here's a snippet,  sorry about the readability its the first version I kinda rushed abit so no documentation,  that's kinda why I'm asking now,  I'm starting over from scratch and trying to give it a little more thought and time
The main goal of the code is to parse a captured serial string,  which I have stored in an array. This time around I'm doubling the controlled channels and adding in more commands to alter settings of the program,
I know I could get away with alot less commands to shorten it but I want it to be somewhat "idiot proof" , the main reason Im worried about speed is basically response time, I'm working on an Android app to control some Rgb lights in my car and I want it to be fast, going for  instantaneous reaction to the corresponding button press on my phone
Thanks for reading and Srry for any grammer error,
  I'm typing this up on my phone which kinda sucks lol



Code:
  if(btcount > 3){
    uint16_t tempval = 0;
    btcount = 0;
   
 Serial.print(char(btbuffer[0]));
 Serial.print(char(btbuffer[1]));
 Serial.print(char(btbuffer[2]));
 Serial.print(char(btbuffer[3]));
 Serial.println(char(btbuffer[4]));
   
    if((btbuffer[0] == 'r' || btbuffer[0] == 'R') && (btbuffer[1] == 'e' || btbuffer[1] == 'E') && (btbuffer[2] == 'd' || btbuffer[2] == 'D') && (btbuffer[3] == 'd' || btbuffer[3] == 'D')){
            analogWrite(ch1, 255);
            analogWrite(ch2,000);
            analogWrite(ch3,000);
            EEPROM.write(10,255);
            EEPROM.write(20,000);
            EEPROM.write(30,000);
            goto endserial;
    } else
        if((btbuffer[0] == 'b' || btbuffer[0] == 'B') && (btbuffer[1] == 'l' || btbuffer[1] == 'L') && (btbuffer[2] == 'u' || btbuffer[2] == 'U') && (btbuffer[3] == 'e' || btbuffer[3] == 'E')){
            analogWrite(ch1, 000);
            analogWrite(ch2,000);
            analogWrite(ch3,255);
            EEPROM.write(10,000);
            EEPROM.write(20,000);
            EEPROM.write(30,255);
            goto endserial;
    } else
        if((btbuffer[0] == 'g' || btbuffer[0] == 'G') && (btbuffer[1] == 'r' || btbuffer[1] == 'R') && (btbuffer[2] == 'e' || btbuffer[2] == 'E') && (btbuffer[3] == 'n' || btbuffer[3] == 'N')){
            analogWrite(ch1, 000);
            analogWrite(ch2,255);
            analogWrite(ch3,000);
            EEPROM.write(10,000);
            EEPROM.write(20,255);
            EEPROM.write(30,000);   
            goto endserial;
    } else
    if((btbuffer[0] == 'p' || btbuffer[0] == 'P') && (btbuffer[1] == 'u' || btbuffer[1] == 'U') && (btbuffer[2] == 'r' || btbuffer[2] == 'R') && (btbuffer[3] == 'p' || btbuffer[3] == 'P')){
            analogWrite(ch1, 200);
            analogWrite(ch2,000);
            analogWrite(ch3,100);
            EEPROM.write(10,200);
            EEPROM.write(20,000);
            EEPROM.write(30,100);   
            goto endserial;
    } else
    if((btbuffer[0] == 'p' || btbuffer[0] == 'P') && (btbuffer[1] == 'i' || btbuffer[1] == 'I') && (btbuffer[2] == 'n' || btbuffer[2] == 'N') && (btbuffer[3] == 'k' || btbuffer[3] == 'K')){
            analogWrite(ch1,200);
            analogWrite(ch2,000);
            analogWrite(ch3,050);
            EEPROM.write(10,200);
            EEPROM.write(20,000);
            EEPROM.write(30,050);   
            goto endserial;
    } else
    if((btbuffer[0] == 'o' || btbuffer[0] == 'O') && (btbuffer[1] == 'r' || btbuffer[1] == 'R') && (btbuffer[2] == 'n' || btbuffer[2] == 'N') && (btbuffer[3] == 'G' || btbuffer[3] == 'g')){
            analogWrite(ch1, 255);
            analogWrite(ch2,050);
            analogWrite(ch3,000);
            EEPROM.write(10,255);
            EEPROM.write(20,050);
            EEPROM.write(30,000);   
            goto endserial;
    } else
    if(((btbuffer[0] == 'c' || btbuffer[0] == 'C') && (btbuffer[1] == 'r' || btbuffer[1] == 'R') && (btbuffer[2] == 'A' || btbuffer[2] == 'a') && (btbuffer[3] == 'Y' || btbuffer[3] == 'y')) || ((btbuffer[0] == 'f' || btbuffer[0] == 'F') && (btbuffer[1] == 'a' || btbuffer[1] == 'A') && (btbuffer[2] == 'd' || btbuffer[2] == 'D') && (btbuffer[3] == 'e' || btbuffer[3] == 'E'))){
            mode = cray;
            craystep = 0;
           analogWrite(ch1, 0);
           analogWrite(ch2, 0);
           analogWrite(ch3,0); 
           Serial.println("Mode set to cray");
            goto endserial;
    } else
    if((btbuffer[0] == 'p' || btbuffer[0] == 'P') && (btbuffer[1] == 'r' || btbuffer[1] == 'R') && (btbuffer[2] == 'o' || btbuffer[2] == 'O') && (btbuffer[3] == 'g' || btbuffer[3] == 'G')){
            mode = program;
           analogWrite(ch1, 255);
           analogWrite(ch2, 255);
           analogWrite(ch3, 255);
          Serial.println("Mode set to program");
            goto endserial;
    } else
    if((btbuffer[0] == 'r' || btbuffer[0] == 'R') && (btbuffer[1] == 'a' || btbuffer[1] == 'A') && (btbuffer[2] == 'n' || btbuffer[2] == 'N') && (btbuffer[3] == 'd' || btbuffer[3] == 'D')){
            mode = randommode;
          Serial.println("Mode set to random");
            goto endserial;
    } else

 
   
    tempval = btbuffer[1] - 48;
    tempval = tempval * 10;
    tempval += (btbuffer[2] - 48);
    tempval = tempval * 10;
    tempval += (btbuffer[3] - 48);
   

 
    if(btbuffer[0] == 'T' || btbuffer[0] == 't' || btbuffer[0] == '9'){
   Serial.print("haha");
  digitalWrite(ch1,1);
  delay(200);
  digitalWrite(ch2,1);
  delay(200);
  digitalWrite(ch3,1);
  delay(200);
  digitalWrite(ch1,0);
  delay(200);
  digitalWrite(ch2,0);
  delay(200);
  digitalWrite(ch3,0);
  delay(200);
  digitalWrite(ch1,1);
  delay(200);
  digitalWrite(ch2,1);
  delay(200);
  digitalWrite(ch3,1);
  delay(200);
  digitalWrite(ch1,0);
  delay(200);
  digitalWrite(ch2,0);
  delay(200);
  digitalWrite(ch3,0);
  delay(200);
    }
    else
    if(btbuffer[0] == 'R' || btbuffer[0] == 'r' || btbuffer[0] == '1'){
      analogWrite(ch1, tempval);
      EEPROM.write(10,tempval);
    }
    else
      if(btbuffer[0] == 'G' || btbuffer[0] == 'g' || btbuffer[0] == '2'){
        analogWrite(ch2, tempval);
        EEPROM.write(20,tempval);
      }
      else
        if(btbuffer[0] == 'B' || btbuffer[0] == 'b' || btbuffer[0] == '3'){
          analogWrite(ch3, tempval);
          EEPROM.write(30,tempval);
        }
        else
          if(btbuffer[0] == 'W' || btbuffer[0] == 'w'){
            analogWrite(ch1, 255);
            analogWrite(ch2, 255);
            analogWrite(ch3,255);
            EEPROM.write(10,255);
            EEPROM.write(20,255);
            EEPROM.write(30,255);
          }
          else
            if(btbuffer[0] == 'O' || btbuffer[0] == 'o' || btbuffer[0] == '0') {
              analogWrite(ch1, 0);
              analogWrite(ch2, 0);
              analogWrite(ch3,0);
              EEPROM.write(10,0);
              EEPROM.write(20,0);
              EEPROM.write(30,0);
              Serial.println("lights off");
            }   
           
    endserial:
    ewrites++;
    EEPROM.write(0,(ewrites & 0xFF00));
    EEPROM.write(1,(ewrites & 0x00FF));
    Serial.print("eeprom writes");
    Serial.println(ewrites);
  }

}
6  Using Arduino / Programming Questions / if else or switch case? on: April 19, 2014, 12:26:21 am
which would be faster and/or less memory?
i have about 25 if else statements, i was wondering if there would be any advantage of using switch case statements instead, i dont mind the look of either, i can use both pretty well, i just dont know if one would be executed faster than the other or maybe use less memory, like the last if else statements has to wait for the first 24 to be checked, but if i did a switch case would it jump directly to the last one if it matched? or would it still check them all and then goto it?
7  Using Arduino / General Electronics / Re: can i put leds on serial line to show activity? on: April 18, 2014, 09:34:26 pm
Thanks for the replies,  and sorry if the question didn't seem very concise,  but I'd say it was answered perfect,  that the leds will not interfere,  also the bit on the normal state of the lines is very helpful,  I kinda assumed they were held low with no activity,  I'm currently designed a board with a 328p and I decided to  throw in those leds as a troubleshoot helper since its going to be connected to a serial Bluetooth module which has no indication of activity
8  Using Arduino / General Electronics / can i put leds on serial line to show activity? on: April 18, 2014, 12:37:34 am
so i was planning on puttings leds directly the rxd/txd to show activity(ofcourse with series 1k resistors), i was just wondering if this would affect the serial transmission at all or if it would even work(as in blink too fast and be useless). i checked out the arduino uno shematic and they power the leds off of a separate output not directly off the lines, i figured this was so they dont affect the serial lines when they are in use, but im not sure, thanks for reading
9  Using Arduino / General Electronics / Re: Reading 0-100 mV signal on: December 17, 2013, 09:39:49 am
You can set the voltage reference to external and put a lower voltage on the aref pin, I'm not exactly how low it can go but you can probably get the range alot closer without any hardware
10  Community / Bar Sport / strange radio outlet? help figuring what it is on: December 12, 2013, 08:37:48 pm
Hey I found this antique outlet in a wall, it has a receptor looking thing on the bottom one labeled ground the other antenna , that isn't confusing, weird part is there are two momentary buttons that when both pressed it seems to short out the outlet below? Any ideas or knowledge on this?
11  Using Arduino / General Electronics / Re: Delaying a digital signal on: September 05, 2013, 07:27:49 pm
Could Just use a 555 timer to delay it,
12  Using Arduino / General Electronics / Re: Bluetooth and Arduino Electromagnetic interference question on: August 29, 2013, 06:36:31 pm
Maybe try a 433 mhz wireless link? There are tons cheap on ebay, tho ive never tried themn
13  Using Arduino / General Electronics / Re: Bluetooth and Arduino Electromagnetic interference question on: August 28, 2013, 08:23:13 pm
 Do you have a difference if you separate the bluetooth module from the rest? As in bring the module out of the casing and as far as possible while still connected
Also another thought would be since the noise is audible perhaps its not radio frequency noise from the bluetooth but noise from the serial transmission, perhaps increasing the baud rate above audible could help, if you bad a ossciloscope and "watched" noise that would helpbyou find its orign,
So maybe try a baud rate like 57600, which can be done with AT commands to the module, exact specs on doing that can be found by searching your module on the internet(looka like hc-05 , same i use)D
14  Using Arduino / Programming Questions / Re: Can-bus shield on: August 26, 2013, 07:36:14 pm
 You  would just have one canbus shield per arduino, they can all communite together assuming one acts as the master(the one that reads), and the other two as slaves(the ones that "write" or reply back to the master,
Just communicate with eaxh one , one at time, to gather the data.u
15  Using Arduino / General Electronics / Re: piezo tweeter to amplifier coupling on: August 26, 2013, 03:07:10 pm
You could probably get away with a much simpler amplifier, a transistor or mosfet would work easily, especially since its a square wave and not an actual analog signal .u
Pages: [1] 2 3 ... 116