Show Posts
Pages: 1 ... 53 54 [55] 56 57 ... 116
811  Using Arduino / Programming Questions / Re: Array of functions (addressing multiple identical sensors) on: January 10, 2013, 06:17:05 am
You could always try this:
Code:
DHT myDHT[MaxSensors] = {DHT(0, 11),DHT(1, 11),DHT(2, 11),DHT(3, 11),DHT(4, 11)};

EDIT: Sorry, those should have been in Capitals, fixed now.
812  Using Arduino / Programming Questions / Re: Algorithm to rotate data on: January 09, 2013, 02:08:01 pm
Same code again, but working bitwise rather than element wise.

Code:
void setup() {
  // put your setup code here, to run once:
  byte array[8] = { 0b00010000,
                    0b00101000,
                    0b01000100,
                    0b11111110,
                    0b10000010,
                    0b10000010,
                    0b10000010,
                    0b00000000 };
  byte rotatedArray[8] = {0};
  /*
  //rotate 90* anti-clockwise
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      char newI = 7-j;
      char newJ = i;
      byte value = ((array[i] >> j) & 1); //extract the j-th bit of the i-th element
      rotatedArray[newI] |= (value << newJ); //set the newJ-th bit of the newI-th element
    }
  }
  */
  //rotate 90* clockwise
  for (char i = 0; i < 8; i++){
    for (char j = 0; j < 8; j++){
      char newI = j;
      char newJ = 7-i;
      byte value = ((array[i] >> j) & 1); //extract the j-th bit of the i-th element
      rotatedArray[newI] |= (value << newJ); //set the newJ-th bit of the newI-th element
    }
  }
 
 
 
  //It should now be reversed. Quick log to check.
  Serial.begin(115200);
  Serial.println("In");
  for (char i = 0; i < 8; i++){
    for (char j = 0; j < 8; j++){
      Serial.print(((array[i]>>j)&1)?'1':'0');
      Serial.print(' ');
    }
    Serial.println();
  }
  Serial.println();
  Serial.println("Out");
  for (char i = 0; i < 8; i++){
    for (char j = 0; j < 8; j++){
      Serial.print(((rotatedArray[i]>>j)&1)?'1':'0');
      Serial.print(' ');
    }
    Serial.println();
  }
}

void loop() {
  // put your main code here, to run repeatedly:
 
}
813  Using Arduino / Microcontrollers / Re: stk500_getsync() not in sync resp=0x00 error for arduino uno breadboard on: January 09, 2013, 11:51:05 am
If it already has optiboot, you don't need to burn the bootloader, they should just work via UART.

How were you wiring them up to the computer?
814  Using Arduino / Programming Questions / Re: Algorithm to rotate data on: January 09, 2013, 11:45:18 am
After a little bit of playing around with how coordinates map, it is really rather simple:
Code:
void setup() {
  // put your setup code here, to run once:
  const char maxSize = 4; //must be a multiple of 2, e.g. 2,4,6,8
  char array[maxSize][maxSize] = {{'A','B','C','D'},{'E','F','G','H'},{'I','J','K','L'},{'M','N','O','P'}};
  char rotatedArray[maxSize][maxSize];
  /*
  //rotate 90* anti-clockwise
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      char newI = maxSize-1-j;
      char newJ = i;
      rotatedArray[newI][newJ] = array[i][j];
    }
  }
  */
  //rotate 90* clockwise
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      char newI = j;
      char newJ = maxSize-1-i;
      rotatedArray[newI][newJ] = array[i][j];
    }
  }
  
  //It should now be reversed.
  Serial.begin(115200);
  Serial.println("In");
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      Serial.print(array[i][j]);
      Serial.print(' ');
    }
    Serial.println();
  }
  Serial.println();
  Serial.println("Out");
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      Serial.print(rotatedArray[i][j]);
      Serial.print(' ');
    }
    Serial.println();
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  
}
Result:
Code:
In
A B C D
E F G H
I J K L
M N O P

Out
M I E A
N J F B
O K G C
P L H D
815  Using Arduino / Programming Questions / Re: Algorithm to rotate data on: January 09, 2013, 10:03:56 am
One approach would be the following:

1) Map each ring into a line starting at the top left and working clockwise. So:
A B C D
E F G H
I J K L
M N O P
Becomes:
outer ring: ABCDHLPONMIE. Ring size = 4
inner ring: FGKJ. Ring size = 2

2) move the last 'ring size - 1' characters to the beginning of a new array
ABCDHLPON  MIE //extract the last 3 as ring size = 4
-> MIE //new array

FGK  J //extract the last 1 as ring size = 2
-> J //new array

3) concatenate the rest:
MIE  ABCDHLPON
J   FGK

4) shift each line back into a ring (inverse of step 1)
M I E A
N J F B
O K G C
P L H D



As for realising it in code, the difficult bit is going to be extracting each ring. But it is doable. If you design a function to extract a ring of a specified size, then you could call that same function for each of the rings in turn, and it could be scaled up to 8x8 easily that way. It would be also sensible to have the function be able to do the inverse to put the lines back into the ring which would be the same code as extracting them only moving flipping destination and source.
I'll write a few lines of code as a possible hint.
816  Using Arduino / Programming Questions / Re: Help with C++ Serial Port Interface with Arduino on: January 09, 2013, 07:48:40 am
You need to create an instance of Serial in order to call non-static functions.
Code:
Serial mySerial = Serial("COM4"); //Create a serial object.

void main() {
  Bool connected = mySerial.IsConnected();
}


This line works because you are calling a constructor function which is by definition static (it creates an instance of a class, so it doesn't require an instance to call it):
Code:
Serial::Serial("COM4");


'static' functions are also known as class methods. These functions do not require any of the instance variables of the class and so can be called directly.

None static functions are known as instance methods. These require instance variables (for example the line "this->connected" accesses the 'connected' variable declared in the class), which means you have to create an instance of the class in memory in order for the function to know where 'connected' is stored in the memory. The 'this' pointer is the memory address of the current instance.
817  Using Arduino / Displays / Re: Very cheap LCD with spongy thing, how's it work? on: January 08, 2013, 06:50:21 pm
The spongey thing is known as an "Elastomeric connector", and is made up of lots of essentially conductive lines. What that means is that if you compress it slightly and have it oriented correctly, it will only conduct in one direction.
By having a long line of the stuff, you can connect multiple pcb pads to multiple non-solderable traces on a display such as the one you have. Each pad will connect to any pad on the display directly above it in the direction of the conductive material, but not to the adjacent pads as it won't conduct in that direction.

The display does have pads on it, but they are made of a transparent conductive material. I have found that it is possible to use conductive glue to attach wires to the displays rather than using the 'sponge'. You just have to be very careful with the quantity of glue you use and keeping the wires in alignment with the traces on the display.

Here is a good reference, with a picture of what the sponge looks like diagramatically:
http://www.fujipoly.com/products/zebra-elastomeric-connectors.html
818  Using Arduino / Programming Questions / Re: objective - C RCOIP.h library on: January 08, 2013, 06:45:04 pm
Perhaps you might find these to be useful references?
http://australianrobotics.com.au/news/iphone-robot-control-with-rctx-app-and-rcoip
http://www.open.com.au/mikem/arduino/RCKit/index.html
819  Using Arduino / Programming Questions / Re: Moving analog data over serial on: January 07, 2013, 05:22:51 pm
It isn't partuclarly crap. "parseInt()" sits there trying to read in values from the Serial port until it either times out (and returns 0), or another character arrives in and it sits there trying to read the next. That means that it doesn't need for Serial.available() to be any more than 1 when you first call it for it to work.

Granted the implementation could be improved, for example, if you send "12-34" it will detect it as -1234, and if it takes too long for the 2nd, 3rd, and so on characters to arrive after each other it will just give up and return.
Also that example doesn't account for the fact that you should wait until Serial.available()>0 in between each of the calls to parseInt().
820  Using Arduino / Programming Questions / Re: problems with softserial and ATtiny85 on: January 07, 2013, 05:02:24 pm
Can I suggest you try the tiny core I wrote?
https://github.com/TCWORLD/ATTinyCore

It has software serial routines which are designed to mimic the way the hardware serial library does, which means you dont need the softwareserial library, simply use the normal Serial.print(), Serial.available(), Serial.read() commands etc. as you would for a regular arduino. There are no set baud rates, and I have had success with rates as high as 115200.

There are two small caveats/differences between it and Hardware serial.
The first is that TX must be digital 0 and RX must be digital 1 (which is just swapping RX and TX in your case). This i because my library uses the built in analog comparator to supply an interrupt vector. It features the same ring buffer as Hardware Serial does meaning that polling is not required.
The second is that is cannot transmit and recieve Serial data at the same time (its Half Duplex), but you don't appear to need to.
821  Using Arduino / Project Guidance / Re: Speedy line follower ( Due/ Raspi/Launchpad, which to use?) on: January 07, 2013, 03:30:08 pm
I suppose I will have to clarify my position...

When you have an Uno, a Mega, and a Due to play with, those would be a far better option when you have to do things such as control the speed of multiple motors accurately.
822  Using Arduino / Microcontrollers / Re: Does the latest IDE support 644P and 1284P? on: January 07, 2013, 03:14:13 pm
I seem to recall reading somewhere that xmegas were though about but were ditched due to reliability and supply issues.

Also, there is an Arduino IDE spinoff for XMegas:
https://github.com/akafugu/Xmegaduino
But I believe they forked the whole IDE, so it isn't as simple as just a new core.
823  Using Arduino / General Electronics / Re: transistor gate does not respond to arduino on: January 07, 2013, 10:23:11 am
They'll do. Just connect the emitter to ground, the collector to the gate of the MOSFET (and a 10k resistor to +12v), and the base via a 1k resistor to the arduino.
824  Using Arduino / General Electronics / Re: transistor gate does not respond to arduino on: January 07, 2013, 09:38:25 am
You are going to have to post a schematic of how the transistor is wired.
825  Using Arduino / Programming Questions / Re: Why does this work in a .h but not in a .ino? on: January 07, 2013, 05:19:00 am
In recent versions. You need 1.0.3 onwards for this to work (or maybe 1.0.2, I can't remember right now).
So it doesn't. I've been using 1.5 as I have a Due, I guess I assumed the two would be similar.
Pages: 1 ... 53 54 [55] 56 57 ... 116