Show Posts
Pages: 1 ... 58 59 [60] 61 62 ... 71
886  Using Arduino / Programming Questions / Re: LCD Menu on: December 17, 2011, 04:34:43 pm
Did you try a google search? this result came up on the first page and looks promising.
887  Using Arduino / Programming Questions / Re: I need some code translated for me. on: December 17, 2011, 04:29:03 pm
void send_address(uint8_t addr) {
   uint8_t i;
   uint8_t temp;
   /* idle high */
   TX_PORT |= _BV(TX_BIT); // digitalWrite(TX_BIT on TX_PORT, HIGH);
   TX_DDR  |= _BV(TX_BIT); // pinMode(TX_BIT on TX_PORT, OUTPUT);
   /* required idle delay w0 (2ms), be safe with 4ms */
   _delay_ms(4); //delay(4);
   /* start bit */
   TX_PORT &= ~_BV(TX_BIT); // digitalWrite(TX_BIT on TX_PORT, LOW);
   /* this is at 5bps */
   _delay_ms(200); // delay(200);
   /* send byte */
   for (i = 0; i < 8; i++) { // go 8 times
      temp = (addr >> i) & 0x01;  //temp is the i-th bit of addr
      if (((TX_PORT & _BV(TX_BIT)) >> TX_BIT) == temp) { // if (digitalRead(TX_BIT) == temp)
         /* already at the correct level, do nothing */
      } else {
         if (0 != temp) { // if temp isn't 0
            TX_PORT |= _BV(TX_BIT); //digitalWrite(TX_BIT, HIGH);
         } else {
            TX_PORT &= ~_BV(TX_BIT); //digitalWrite(TX_BIT, LOW);
      _delay_ms(200); //delay(200);
   TX_PORT |= _BV(TX_BIT); //digitalWrite(TX_BIT, HIGH);
   _delay_ms(200);  //delay(200);
   /* already idling high on TX */

The entire thing is essentially a copy of shiftOut()
888  Using Arduino / Programming Questions / Re: Tx/Rx as digitals on Mini on: December 17, 2011, 01:36:09 am
I recently had a similar need for more I/O pins ;-)

You can do it, but you must disable the UART the 'hard way'. It is activated by default and overrides the pin-direction (input/output) internally in hardware. Once you've disabled it you cannot use any hardware serial communication anymore (in that program).

Insert this at the very beginning of setup()

UCSR0A = 0x00;
UCSR0B = 0x00;
UCSR0C = 0x03;

This sets the uart control & status registers to their default values and turns the uart + port override off.

At the end of the arduino init() function it does this.
889  Using Arduino / Sensors / Re: gyro sensor on: December 17, 2011, 12:40:04 am
void loop() {
  static unsigned int angle = 0;
  static unsigned long lastTime = 0;
  static unsigned long time;
  anglerate= analogRead(2);
  /*Scale anglerate so that it's in degrees per millisecond, centered around 0 - depends on specific gyroscope*/
  time = millis();
  angle += anglerate * (lastTime - time); /* This is the important part */
  lastTime = time;

If you look up integrals, the second to last line (angle +=...) is what is doing the integration. anglerate is the height of the rectangle, and (lastTime - time) is dx. In a real integral, they say that dx is infinitely close to 0, but in real life, you can only get so accurate so dx is just the time per loop.
890  Using Arduino / Sensors / Re: gyro sensor on: December 16, 2011, 10:53:40 pm
If you add up all of the speeds (the output of the gryo) you'll get the angle. It's called integrating (from calculus, but it's not difficult at all). You can use the angle to tell the helicopter to lift up one side more or less so that it's always horizontal.
891  Topics / Science and Measurement / Re: New oscilloscope (without Java) on: December 16, 2011, 10:34:35 pm
I think the previous comment is in the wrong thread. Otherwise please elaborate how it relates to my oscilloscope project.

Your oscilloscope project gets data from the arduino and displays it fancily, correct? However, the arduino presumably needs to have a program on it to send back the data. I'm suggesting adding a button that puts that program on the arduino.
892  Using Arduino / Programming Questions / Re: Need help using millis() on: December 16, 2011, 09:14:20 pm
So...something like this?

unsigned long currentTime = 0;    //Current clock time
unsigned long previousTime = 0;   //Store last time motor ran
unsigned long motorOntime = 5000; //Time motor will on
unsigned long motorOfftime = 5000;//Time motor is off
int motorRunningflag = 0;         //0 = motor is off, 1 = motor is on

Should millis() be in there somewhere?

In that section of code? Do you need a clock to tell you how long to cook a turkey?
893  Topics / Science and Measurement / Re: New oscilloscope (without Java) on: December 15, 2011, 11:05:11 pm
How do you upload the correct program to the arduino?

How about adding a button? Just grab a makefile off the internet and have a button that applies it. (Or, assume it's an uno and just call avrdude directly.)
894  Using Arduino / Programming Questions / Re: calling an array on: December 12, 2011, 10:47:51 pm
The elements are 0, 1, 2, 3, and 4. You're doing it right, just with the wrong number.
895  Using Arduino / Programming Questions / Re: Im getting an error: expected unqualified-id before "{" token, can someone help? on: December 11, 2011, 06:16:48 pm
Everything needs to be inside either the "setup" or "loop" functions. The way you define a function (including setup and loop) is:

return_type function_name(arguments) {

So, for setup() where it doesn't take any arguments and doesn't return anything, you'd say
void setup() {
  // Whatever you want to run once

If, in the arduino IDE, you go to tools -> auto-format, that will indent everything for you so you can make sure you have a } for each {. However, you have to make sure they're in the correct spots yourself (for example, not having a { at the beginning of the program and putting it after setup() )
896  Using Arduino / Programming Questions / Re: Arduino-Serial DC Motor Control ?'s on: December 09, 2011, 12:38:00 am
Hit modify, select the entire code and press that # button in that toolbox above your message.

Post a link to what motor shield you're using - is there a reason that you're not using the (probably) provided library for it? That will make speed control easy. If you don't use it, check out the analogWrite() function.

That code looks like it should do what you want - does it? If not, post exactly what it does and what you want it to do.
897  Using Arduino / Programming Questions / Re: arduino sketch with gyro sensors on: December 09, 2011, 12:34:38 am
Sure, that should work if you change the constants at the top. However, if you're going to be making something that's complicated and relies on fast updates, I'd try to get rid of all of the float variables and change them to integers. Floating point is s-l-o-w and is completely unnecessary for your application.

Just make sure you keep very good track of what means what. if you're multiplying everything by 1000 so you have an angle of 0 to 360,000, PUT A COMMENT IN.
898  Using Arduino / Programming Questions / Re: Need help with multiple proximity sensors and relays. on: December 08, 2011, 11:51:26 pm
It'd be better if you simply included your code in the body of your message.

You need to figure out the logic before you start programming. It looks to me like there are four cases: sensor1 TRUE and sensor2 TRUE, sensor1 TRUE and sensor2 FALSE, sensor1 FALSE, and sensor 2 FALSE, and sensor1 FALSE and sensor2 TRUE. What do you want to do in EACH of those cases? Then, after saving the two states of the sensors, put in logic to do what you want (whenever you say OR replace with || and whenever you say AND replace with &&)
899  Using Arduino / Programming Questions / Re: Thoughts and musings on Arduino precision on: December 08, 2011, 11:47:39 pm
unsigned long currentMicros = 0;
unsigned long previousMicros = 0;
(void setup, declare an output pin, etc)
void loop(){
currentMicros = micros();
if ( (currentMicros-previousMicros)>=1000000UL){ // 1 second passed?
digitalWrite (outputPin, toggle);
toggle=1-toggle; // set up for next pass.  results in 1,0,1,0
//========Redundant? ===================
previousMicros = currentMicros+1000000UL;  // set up for next second
// ==================================

900  Using Arduino / Programming Questions / Re: arduino shuts down.. serial overflow? on: December 05, 2011, 11:09:10 pm
    TV.draw_circle( - 6, - 6, 6, 1 ); 

This is really bad. How do you know that the compiler doesn't decide to put the function call for the second argument ( before the first argument ( - 6)? This actually results in what's called undefined behavior source, point 4 where the compiler is allowed to do it either way, meaning that it may do what you want for this compiler, or maybe just this *version* of this compiler, or maybe even just for this particular sketch (where the registers line up just right), but may change at any point.

Use a temp variable instead:
char temp =;
TV.draw_circle(temp - 6, - 6, 6, 1 );
Pages: 1 ... 58 59 [60] 61 62 ... 71