Show Posts
Pages: 1 ... 14 15 [16] 17 18 ... 259
226  Using Arduino / Programming Questions / Re: Faster Shiftout, how? on: September 02, 2014, 12:44:12 pm
Quote
uint16_t i;                        // with  uint8_t  imax= 255  too  low for 384 bits
   for (i = 0; i < 383; i++)   // i<8 is for transmiting byte   --> i<383 is for transmiting 384 bits
What? Did I miss something?

val is a byte,  8 bits, and you want to shift through it 384 bits(48 bytes)?

You can probably save a few cycles if you rewrite the digitalWrite function, and take out the IF statements.

The shiftout function is written correctly, granted some overhead can be taken out, but for the most part it is correct. However the SPI library, could be a better choice to use in this case.

Edit: CrossRoads beat me to it.
227  Using Arduino / Project Guidance / Re: How to programme robot arm positions on: September 02, 2014, 11:23:39 am
Quote
I've just plugged my arm in and it's not happy
How so? Did it come with its own servo controller and power supply, or just the arm and servos by themselves?

What did you use to power the servos?
228  Using Arduino / Programming Questions / Re: analogWrite > 255 by accident on: September 02, 2014, 11:15:23 am
These libraries are out dated, so why can't we, the community remake or update the core files? We use them all the time, and we are the ones who spot the mistakes, so why can't we be allowed fix and distribute them? Or tell the original creators what to fix and have them update the libraries?
229  Using Arduino / Programming Questions / Re: analogWrite > 255 by accident on: September 02, 2014, 11:06:37 am
So and I have been wondering this for long time, if certain functions only use values within a byte range, then why are they defined as type int and not byte?

Quote
void analogWrite(uint8_t pin, int val)


Is it just for convenience so that user can input a value greater than 255 and less than 0, only to be rolled over?
230  Using Arduino / Programming Questions / Re: analogWrite > 255 by accident on: September 02, 2014, 10:41:55 am
Im pretty sure it just rolls over and takes the difference, because if you look at the wiring_analog file, it just has this.

Quote
if (val == 0)
   {
      digitalWrite(pin, LOW);
   }
   else if (val == 255)
   {
      digitalWrite(pin, HIGH);
   }
   else
   {
           .
           .
           .
       }

There could be something with the timers that could cap the signal, but I don't know enough about the timers to say for certain. There is nothing to prevent the value from going below 0 or above 255, so something must be taking precedence.
231  Using Arduino / Programming Questions / Re: What is wrong with this code???? on: September 02, 2014, 10:30:09 am
The reason for your first error with GO_DEVICE is this, what was declared in the enum was written as G0_DEVICE, it was a zero, not the capital letter O.

Second after that was fixed, the next two errors would have been digital.Write(8,LOW); <-Should not have a period and it was missing a semicolon. It should be digitalWrite(8,LOW);

Same goes for the one below that.

Fixed.
Code:
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "Platform.h"
#include "SoftwareSerial.h"
#ifndef CDC_ENABLED
// Shield Jumper on SW
SoftwareSerial port(12,13);
#else
// Shield Jumper on HW (for Leonardo)
#define port Serial1
#endif
#else // Arduino 0022 - use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
NewSoftSerial port(12,13);
#endif

#include "EasyVR.h"

EasyVR easyvr(port);

int LED = 8 ;

//Groups and Commands
enum
{
  GROUP_0  = 0,
  GROUP_1  = 1,
};

enum Group0
{
  GO_DEVICE = 0, // fixed
};

enum Group1
{
  G1_LED_ON = 0,
  G1_LED_OFF = 1,
};


EasyVRBridge bridge;

int8_t group, idx;

void setup()
{
#ifndef CDC_ENABLED
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }
  // run normally
  Serial.begin(9600);
  Serial.println("Bridge not started!");
#else
  // bridge mode?
  if (bridge.check())
  {
    port.begin(9600);
    bridge.loop(port);
  }
  Serial.println("Bridge connection aborted!");
#endif
  port.begin(9600);

  while (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    delay(1000);
  }

  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(0);

  group = EasyVR::TRIGGER; //<-- start group (customize)
}

void action();

void loop()
{
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)

  Serial.print("Say a command in Group ");
  Serial.println(group);
  easyvr.recognizeCommand(group);

  do
  {
    // can do some processing while waiting for a spoken command
  }
  while (!easyvr.hasFinished());

  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

  idx = easyvr.getWord();
  if (idx >= 0)
  {
    // built-in trigger (ROBOT)
    // group = GROUP_X; <-- jump to another group X
    return;
  }
  idx = easyvr.getCommand();
  if (idx >= 0)
  {
    // print debug message
    uint8_t train = 0;
    char name[32];
    Serial.print("Command: ");
    Serial.print(idx);
    if (easyvr.dumpCommand(group, idx, name, train))
    {
      Serial.print(" = ");
      Serial.println(name);
    }
    else
      Serial.println();
    easyvr.playSound(0, EasyVR::VOL_FULL);
    // perform some action
    action();
  }
  else // errors or timeout
  {
    if (easyvr.isTimeout())
      Serial.println("Timed out, try again...");
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);
    }
  }
}

void action()
{
  switch (group)
  {
  case GROUP_0:
    switch (idx)
    {
    case GO_DEVICE:
      
        group = GROUP_1 ;

      // write your action code here
      // group = GROUP_X; <-- or jump to another group X for composite commands
      break;
    }
    break;
  case GROUP_1:
    switch (idx)
    {
    case G1_LED_ON:
      digitalWrite(8,HIGH); // fixed
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
    case G1_LED_OFF:
      digitalWrite(8,LOW); //fixed
        // write your action code here
        // group = GROUP_X; <-- or jump to another group X for composite commands
        break;
      group = GROUP_0;
      delay(5);
    }
    break;
  }
}
232  Using Arduino / Project Guidance / Re: I'm trying to make a pole move, fast on: September 01, 2014, 09:39:29 pm
An air piston maybe? What is this for?
233  Using Arduino / Project Guidance / Re: Countdown Timer Help Please on: September 01, 2014, 08:30:57 pm
The button is wired to be brought low when pressed, not high.
234  Using Arduino / Project Guidance / Re: Countdown Timer Help Please on: September 01, 2014, 08:22:19 pm
Did you try the code I posted?
235  Using Arduino / Project Guidance / Re: Countdown Timer Help Please on: September 01, 2014, 07:50:36 pm
Have you taken a look at the Blink without Delay example sketch?

You can play around with this.
Code:
const byte buttonPin = 2;
int timer = 15;
uint16_t prevTime = millis();

void setup()
{
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
  byte button = digitalRead(buttonPin);
  if((millis() - prevTime >= 1000) && (button == LOW) && (timer >= 0))
  {
    prevTime = millis();
    Serial.println(timer);
    timer--;
  }
  if((timer <= 0) && button == HIGH)
    timer = 15;
}

236  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 07:20:11 pm
I am home now.

This is if the data you're sending is sent as individual chars and not just bytes.
Code:
byte Red=0, Green=0, Blue=0, Counter = 0;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  if(Serial.available() >= 9) // see if 9 chars are in the buffer
  { 
    Counter = 0; // make sure the counter is set to 0
    Red = Green = Blue = 0; // reset the color variables
   
    while(Counter <= 9) // while the counter is less than or equal to 9, read the chars from the buffer
    {
      char Tmp = Serial.read(); // read chars from buffer

      switch( Counter / 3) //changed
      {
      case 0:
        Red = Red * 10 + (Tmp - '0'); // convert the chars into integers
        break;

      case 1:
        Green = Green * 10 + (Tmp - '0');
        break;

      case 2:
        Blue = Blue * 10 + (Tmp - '0');
        Serial.print(Red);Serial.print(Green);Serial.println(Blue);
        break;
      }
      Counter++; // increment the counter
    }
  }
}
237  Using Arduino / Programming Questions / Re: Merging Bluetooth initializer code with running code on: September 01, 2014, 06:44:21 pm
I didn't change anything with the bluetooth coding. Maybe change Serial.begin(115200) back to 9600.
238  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 03:21:58 pm
Ok, so instead of using the module operator just use division.
switch( Counter / 3 )
239  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 03:00:05 pm
Something like this is all that is needed. Not tested and more is needed to be added in for a full working code. I am not home to complete this, so could someone else finish this? Thank you.

Code:
byte Red=0, Green=0, Blue=0, Counter = 0;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  if(Serial.available() >= 9)
  {
     char Tmp = Serial.read();
     Counter++;
     
     switch( Counter / 3) //changed
     {
         case 0:
              Red = Red * 10 + (Tmp - '0');
              break;
   
         case 1:
              Green = Green * 10 + (Tmp - '0');
              break;

         case 2:
              Blue = Blue * 10 + (Tmp - '0');
              break;
         }
     }
     else
        Counter = 0;

     /* write a piece that resets the colors back to zero for the next sent string */
}
240  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 01:42:47 pm
I wa refering to what I wrote in reply #3 of that link, but if the data IS always 9 characters long then a simple counter and the uses of the module operator will be perfect for your solution.

See if the serial buffer(Serial.available() ) has first collected 9 chars, then once it has read them in one at a time and increment a counter. You can use an array to store the 3 chars and use atoi() to convert the chars into an actual integer. Then using if(counter % 3) you can change to the next variable.

Rinse and repeat.
Pages: 1 ... 14 15 [16] 17 18 ... 259