|
766
|
Using Arduino / Programming Questions / Re: trouble passing array across serial
|
on: February 05, 2012, 01:42:15 am
|
Third. This is almost certainly not what you meant: (val = Serial1.read()) ==0x7fff). val = Serial1.read() is an assignment operation. In the context of an if-statement that will return whether or not the assignment operation succceded or not (and it will). That evaluates down to (if TRUE == 0x7FFF). I see no reason for the "val =".
operator= returns the value (this is why you can do a=b=0), so that statement could be valid. However, HardwareSerial::read() returns one byte, so it will never equal 0x7fff
|
|
|
|
|
767
|
Using Arduino / Programming Questions / Re: 'DDRD', 'DDRC', 'TCCR1A' ... was not declared in this scope: error
|
on: February 05, 2012, 01:35:18 am
|
ATtiny85 doesn't have all of the 328's ports, etc. Its limited I/O is on PortB. Is "Arduino-Tiny" supposed to figure that out for you?
That is indeed a distinct possibility and I was hoping that Arduino-Tiny figures that out. One explanation is that DigitalWriteFast library bye-passes Arduino-Tiny completely, i.e. doesn't use Arduino pin-mapping logic, so I think that mright explain the error messages. But aren't those constant defined in avr-libc headers ? They're only defined if the processor has the corresponding port. If you're not using the port, just comment out the code that uses it. That's probably the most trivial thing you can do while still calling it "porting" I'm assuming you're saying "constant" because they refer to a constant memory address, because I really hope you don't think DDRD is a constant.
|
|
|
|
|
768
|
Using Arduino / Programming Questions / Re: Math.h
|
on: February 01, 2012, 01:34:28 am
|
I'm sorry if this question seems dumb but when I got to Sketch and Import, I can't find "Math" in there. Also, If I manually add "#include <math.h>" the math part doesn't turn yellow like in other includes. I hope I can show this in the pictures.
EDIT: The same thing happens even if the math.h is capitalized.
That's not a question. Is the fact that your source code doesn't change colors problematic? The include menu only looks for files in the two "library" sections. It doesn't look in the system wide default locations like /usr/include and /usr/avr/include. Essentially the same for the color changing.
|
|
|
|
|
770
|
Using Arduino / Microcontrollers / Re: Arduino Uno Rev3 pinouts photo
|
on: January 30, 2012, 02:05:16 am
|
I find that the pins on the ICSP header (on the right) are useful for grabbing an extra +5/Gnd combination if I need to power other devices (or for hooking up a multimeter or logic analyzer).
I generally use the giant USB socket for a gnd to connect my multimeter to.
|
|
|
|
|
771
|
Using Arduino / Programming Questions / Re: Doubts about the BYTE command
|
on: January 28, 2012, 02:21:35 am
|
|
no, BYTE (in caps) was a macro that was usually passed to the Serial.print commands to print an actual number rather than a character. If the compiler is warning you about byte (lowercase), ignore it. If it's error'ing you, post your code that doesn't compile. I've used byte (lowercase) many times in 1.0
|
|
|
|
|
772
|
Using Arduino / Programming Questions / Re: Small help needed with #Define
|
on: January 24, 2012, 02:12:18 am
|
"#define BIT_IS_SET(i, bits) (1 << i & bits)" 1 << i
This means take the number 1 (the first "1"): 00000001 then "shifting" it right i bits. So if i was 4, 1<<i would be 00010000 See, the 1 is now 4 digits more to the left. This is exactly the same as saying i * 16 // 16 is 2^4 The & is the bitwise AND. This means that it cycles through each bit in each byte, and if they are the same, it makes the corresponding resulting bit 1. Example: 01011001 & 11011101 = 01011001 Since 1<<i will be all zeros except for one digit, the answer will either have all 0's if that bit wasn't 1, or one 1 if the bit was one. Lucky for us, C interprets any value that's not 0 as "true" in an if-statement. So, all in all, that define checks whether or not the "i"th bit of "bits" is 1.
|
|
|
|
|
774
|
Using Arduino / Programming Questions / Re: Digital port programming, interrupt disable why?
|
on: January 20, 2012, 05:05:50 pm
|
void setup() { Serial.println("This is my favorite sketch"); }
void loop() { Serial.println("I'm entering a time-sensitive part of the program!"); noInterrupts(); digitalWrite(4, HIGH); delayMicroseconds(1000); Interrupts(); }
Good thing digitalWrite doesn't enable interrupts, or this wouldn't work* *assuming it did anything
|
|
|
|
|
775
|
Using Arduino / Programming Questions / Re: Redirect Timer0 to own function and continue with original Arduino Timer0 ISR
|
on: January 20, 2012, 04:57:03 pm
|
The interrupt vector is stored in the PROGRAM (FLASH) space. This means it cannot be changed during program execution. I don't know of a way to implement an ISR for timer0 using the Arduino IDE. Also, I don't know how you came up with 976,56 Hz (976.56 Hz for the rest of us), but the prescaler is set to 64 so the frequency is 16.000.000 / 64 which equals 250kHz.
The interrupt itself only fires when the timer overflows. Remember, the millis interrupt fires every millisecond (1kHz) OP, I don't think there is any way without editing wiring.c. If you want to do that, just make it: void (* periodicFunc)(void) = 0; #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) SIGNAL(TIM0_OVF_vect) #else SIGNAL(TIMER0_OVF_vect) #endif { // copy these to local variables so they can be stored in registers // (volatile variables must be read from memory on every access) unsigned long m = timer0_millis; unsigned char f = timer0_fract;
m += MILLIS_INC; f += FRACT_INC; if (f >= FRACT_MAX) { f -= FRACT_MAX; m += 1; }
timer0_fract = f; timer0_millis = m; timer0_overflow_count++; if (periodicFunc) periodicFunc(); } then write a function and say periodicFunc = myISR;
|
|
|
|
|
777
|
Using Arduino / Programming Questions / Re: two dimensional array declaration
|
on: January 19, 2012, 03:49:19 pm
|
The syntax is like this: int coolarray[2][4] = { {2, 5, -12, 4}, {4, 6, 2993, -1002 } };
Although you can get away with this: int coolarray[][] = { {2, 5, -12, 4}, {4, 6, 2993, -1002 } };
since the compiler can see "oh, it's four by two!" If you want to pack 8 bools into a byte, you can do this: char arrayofbits [] = { 0b11001111, 0b01111000, 0b10001111, };
or you could use a union (google it)
|
|
|
|
|
778
|
Using Arduino / Programming Questions / Re: How to create a library that requires another libray
|
on: January 19, 2012, 01:11:36 pm
|
...
that's all true. To destroy an instance of a class, you can just let it go out of scope, or use delete if you allocated it with new. To access fish in the second example, you would do something like: class Morse { public: Morse(int pin); void dot(); void dash(); int fish; private: int _pin; };
Morse morse(3); morse.fish = 5; int y = morse.fish morse.dot(); morse.dash();
However, you almost never want to actually have a variable with public scope; people generally make get and set functions. class Morse { public: Morse(int pin); void dot(); void dash(); int getFish() { return fish; } void setFish(int val) { fish = val; } private: int fish; int _pin; };
|
|
|
|
|
779
|
Using Arduino / Programming Questions / Re: detect falling object with infra red (urgent)
|
on: January 18, 2012, 07:04:25 pm
|
What is ISR? First i thought it was a typing error for IR. It's a function that gets run when an "interrupt" happens. An interrupt is usually triggered by a pin change or a timer (in your case, it would be a pin change), and it just pauses whatever the code is currently doing and calls the function, then goes back to whatever it was doing. I'm also questioning how you managed to get a good digitalread value on an analog signal, but that's great if it works.
I think when using digital read on a analog signal that below 512 is 0 and above 512 is 1 (that's my guess). Nope. Generally, it will read HIGH if it's above about 2.7V, LOW if it's under about 0.3V, and whatever it wants between the two. For speed, I'd suggest getting something like an analog comparator that can take an analog signal and say "under" or "over" for a certain voltage. I will look at direct port acces.
That will have the same problems as I just mentioned, but it will be faster. However, if the digitalRead'ing works somehow, direct port access will also.
|
|
|
|
|
780
|
Using Arduino / Programming Questions / Re: unknown IR receiver error
|
on: January 18, 2012, 06:56:04 pm
|
Sorry for pushing that thread, but i'm looking for a solution for the same thing here...
Well, part of the problem is that translating code from the atmega to that attiny is that the atmega can do more stuff than the attiny - it has more pins and it has more timers. So, when you say you want to make the code run on the attiny, it can be like saying you want your bike to go 100 km/h. Depending on how many timers the attiny has (I'm not an expert) you could make the library use timer1. If it only has one timer (which is used up by millis) it's best to throw out the library and start over. Come to think of it, I wrote a library that does essentially the same thing but doesn't use any timers, so it should be relatively easy to port to an attiny -- PM me if you want it.
|
|
|
|
|