Show Posts
Pages: 1 [2] 3 4 ... 278
16  Using Arduino / Programming Questions / Re: Optimising repetitive code on: June 13, 2014, 06:32:13 pm
Pointers... no, you don't want pointers yet smiley-razz

Arrays are your friend.  Instead of a, b, c, d, e etc, use bitVal[0], bitVal[1] bitVal[2] etc, or in a loop:

Code:
byte val = 0;
byte bitVal[8] = {1, 0, 0, 1, 1, 1, 0, 1};

for (byte i = 0; i < 8; i++) {
  bitWrite(val, i, bitVal[i]);
}
17  Using Arduino / Programming Questions / Re: "Grouping" integer values from an array on: June 13, 2014, 06:05:52 pm
Hell no.  Stay away from String like the plague!

It's as simple as:
Code:
data[0] += '0';
data[1] += '0';
data[2] += '0';
data[3] = 0;
Serial.println((char *)data);

Add '0' to each entry of the array.  Remember, a character is just a human representation of a number, so just add a pre-set number to each entry so it represents the right character (in this case '0' - the ASCII character 0 not the integer 0).  Slap 0 on the end (C string terminating NULL character) and treat it like a C string (cast it to char *).
18  Using Arduino / Programming Questions / Re: Concat integer values from an array on: June 13, 2014, 05:40:52 pm
You could add '0' to each one, and add a character 0 to the end of the array - thus turning it into a string.
19  Using Arduino / Programming Questions / Re: Is a serial monitor attached? on: June 13, 2014, 04:31:15 pm
If you don't break the connection with reset, every time you open the serial port the board will reset.  Do you really want that?

If you don't cut the connection (or somehow otherwise disable it) then you'll know that the serial port is open because the board will have just reset, so there'll be no point in the wire link.
20  Using Arduino / Programming Questions / Re: Is a serial monitor attached? on: June 13, 2014, 04:13:20 pm
Add a switch to the USB socket.
How would that help to know if the serial port is opened on the PC?

PEOPLE: READ THE FRELLING QUESTION, YOU'RE MAKING NO SENSE
21  Using Arduino / Programming Questions / Re: Getting the time on: June 13, 2014, 03:55:40 pm
Google: "Arduino RTC"

You need more than just an arduino to do accurate timer operations over long periods (more than a few seconds).
22  Using Arduino / Programming Questions / Re: Is a serial monitor attached? on: June 13, 2014, 03:13:07 pm
You would need to add a wire to monitor the line - if it even changes.
DTR is programmed to only go low to create a reset when the USB is plugged in, or to start a download.
I think RTS also.
May not be able to get there.
Laptops, the monitor is always attached, yes?
Desktop,  unplug yours and see what happens. I suspect nothing, pretty sure the coms from video card to the monitor is 1-way.
I think you're getting confused.  By "monitor" in this context he means the SERIAL monitor...!

And DTR (or bit 0 of the SET_LINE_STATE message) is set 1 when the serial port is opened, and RTS (or bit 1 of the SET_LINE_STATE message) is set 1 when the PC is able to receive (only meant to be actively used in half duplex communications).
23  Using Arduino / Programming Questions / Re: Is a serial monitor attached? on: June 13, 2014, 02:57:41 pm
Using the Leonardo, yes, you can:
Code:
if (Serial) {
  // Your serial output here
}
For the Uno and other similar boards you would have to do a hardware modification - break the DTR->RESET connection and solder in a wire between the DTR output of the USB chip (before the capacitor) and an IO port of the main MCU.  Of course, that then makes it harder to upload sketches as you have to manually reset the MCU at the right time to enter the bootloader.
24  Using Arduino / Programming Questions / Re: battery Status command on: June 13, 2014, 08:54:37 am
Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Battery: OK");
}
When it stops printing "Battery: OK" you know the battery is flat.
25  Using Arduino / Programming Questions / Re: battery Status command on: June 13, 2014, 08:47:46 am
Not without us knowing what your battery power system might consist of.
26  Using Arduino / Programming Questions / Re: function order in scketch on: June 11, 2014, 08:01:12 am
The preprocessor cannot handle variadic arguments at all.  It has no clue what they are.  You will have to either move the function or create your own prototype for it above where you first call it.

BTW, in the latest beta version of UECIDE this is handled properly smiley-wink

Test sketch:
Code:
void setup() {
}

void loop() {
}

void foo(int a, ...) {
}
Arduino-generated CPP file:
Code:
#line 1 "sketch_jun11a.ino"
#include "Arduino.h"
void setup();
void loop();
#line 1
void setup() {
}

void loop() {
}

void foo(int a, ...) {
}
UECIDE generated CPP file:
Code:
#include <Arduino.h>
#line 1 "untitled4.ino"
void setup();
void loop();
void foo(int a, ...);
#line 1 "untitled4.ino"
void setup() {
}

void loop() {
}

void foo(int a, ...) {
}
27  Using Arduino / Programming Questions / Re: function order in scketch on: June 11, 2014, 06:24:09 am
Chances are the preprocessor isn't identifying them as you are using some structures of types that it doesn't like.  In these cases you will have to either move them to before they are called, or craft your own manual function prototypes.

Normally you'd have to do these things anyway, but the Arduino IDE teaches you some very bad habits by trying to let you define functions after you call them.
28  Using Arduino / Programming Questions / Re: reading CD4021BE shift in register on: June 10, 2014, 11:45:31 am
Well, firstly:
Code:
byte whichSwitch[] = {'left', 'right', 'up', 'down', 'ok', 'back', 'options'};
makes no sense.  You can't store the string 'left' in a byte.  You need 5 chars for that: 'l', 'e', 'f', 't' and '\0'.  I think you want to rethink how you do that.

29  Using Arduino / Programming Questions / Re: reading CD4021BE shift in register on: June 10, 2014, 11:20:44 am
With no buttons pressed, what value do you get?

With just one button pressed, what value do you get?
30  Using Arduino / Programming Questions / Re: reading CD4021BE shift in register on: June 10, 2014, 10:41:25 am
I would suggest writing a much simpler program to start with.  Begin with the basics: shift in a value from the shift register and display the value on the LCD.  When you know you have that working you can expand it out to react to different buttons.
Pages: 1 [2] 3 4 ... 278