Show Posts
Pages: 1 ... 17 18 [19] 20 21 ... 49
271  Using Arduino / Programming Questions / Re: Pin conflict - servos/easyVR on: April 20, 2013, 05:40:22 pm
I am curious of how you have the servos powered.  You say that moving the signal wire to another pin, burnt the servo.  I don't see how that could happen unless you mixed the wires up from the supply.
272  Using Arduino / LEDs and Multiplexing / Re: Driving many Led's From Four Shift registers on: April 20, 2013, 11:59:02 am
Code:
/////////////////////////////////////////////////////
 //This is Sequence 3
 ////////////////////////////////////////////////////
void sequence3(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister3();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister3();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
  sr1Colour = 2; //Set SR1 to red
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Sequence 4
////////////////////////////////////////////////////
void sequence4(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister3();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister4();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
  sr1Colour = 1; //Set SR1 to Green
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Sequence 5
////////////////////////////////////////////////////
void sequence5(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister5();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister5();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Sequence 6
////////////////////////////////////////////////////
void sequence6(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister6();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister6();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Sequence 7
////////////////////////////////////////////////////
void sequence7(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister7();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister7();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Sequence 8
////////////////////////////////////////////////////
void sequence8(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister8();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister8();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Final Sequence 1
////////////////////////////////////////////////////
 void sequenceFinal1(){
   sequence5();
   sequence7();
 }
/////////////////////////////////////////////////////
 //This is Final Sequence 2
////////////////////////////////////////////////////
void sequenceFinal2(){
   sequence5();
   sequence8();
 }
/////////////////////////////////////////////////////
 //This is Final Sequence 3
////////////////////////////////////////////////////
void sequenceFinal3(){
   sequence6();
   sequence7();
 }
/////////////////////////////////////////////////////
 //This is Final Sequence 4
////////////////////////////////////////////////////
void sequenceFinal4(){
   sequence6();
   sequence8();
 }
273  Using Arduino / LEDs and Multiplexing / Re: Driving many Led's From Four Shift registers on: April 20, 2013, 11:58:16 am
Maybe PaulS or someone can go through it.  There's stuff that I don't even understand..

Had split it between 2 posts.  9500 character limit needs to be raised since we have to post code.

Code:
#include <Button.h>

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int outputEnablePin = 3;
int ledPin = 10;
//Button trigger = Button(2,LOW);
int sr1Colour = 0;  // Set for ShiftReg1 as 0 = off, 1 = green, 2 = red
int sr2Colour = 0;

byte leds = 0;
byte button[] = {8, 9};
byte switch_value = 0;
boolean btnOn = false;
int count = 0;

#define NUMBUTTONS sizeof(button)
byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];

void setup() {
  setBrightness(0);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  pinMode(outputEnablePin, OUTPUT);
  //pinMode(2,INPUT); //Trigger switch sits on pin 2
  Serial.begin(9600);
  Serial.println("Welcome");
  byte i;
  
   for (i=0; i< NUMBUTTONS; i++) {
    pinMode(button[i], INPUT);
    digitalWrite(button[i], HIGH);
  }
    //Timer2 Overflow Interrupt Enable
  TIMSK2 |= 1<<TOIE2;
}
//byte pressCount1 = 0;
SIGNAL(TIMER2_OVF_vect) {
  check_switches();
}

void check_switches()
{
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  byte index;

  for (index = 0; index < NUMBUTTONS; index++) {
    currentstate[index] = digitalRead(button[index]);   // read the button
    /*    
    Serial.print(index, DEC);
    Serial.print(": cstate=");
    Serial.print(currentstate[index], DEC);
    Serial.print(", pstate=");
    Serial.print(previousstate[index], DEC);
    Serial.print(", press=");
    */
    
    if (currentstate[index] == previousstate[index]) {
      if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
          // just pressed
          justpressed[index] = 1;
          count = count+1;
          //switch_value = switch_value + 1;

      }
      else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
          // just released
          justreleased[index] = 1;
      }
      pressed[index] = !currentstate[index];  // remember, digital HIGH means NOT pressed
    }
    //Serial.println(pressed[index], DEC);
    previousstate[index] = currentstate[index];   // keep a running tally of the buttons
  }
}


void loop() {
 /////////////////////////////////////////////////////
 //This is Button 1 Set Press
 /////////////////////////////////////////////////////
  
  if(justpressed[0] && btnOn)
  {
    count;
    sequence2();
    justpressed[0] = 0;
    btnOn = false;
  }  
  if(justpressed[0]) {
    Serial.println("Button 0 pressed");
    btnOn = true;
    count;
    justpressed[0] = 0;
    sequence1();
   }
//  /////////////////////////////////////////////////////
// //This is Button 2 Set Press
// /////////////////////////////////////////////////////
if(justpressed[1] && btnOn)
  {
    count;
    sequence1();
    justpressed[1] = 0;
    btnOn = false;
  }  
  if(justpressed[1]) {
    Serial.println("Button 1 pressed");
    btnOn = true;
    count;
    justpressed[1] = 0;
    sequence2();
   }
//  /////////////////////////////////////////////////////
// //Run final Sequence1
// /////////////////////////////////////////////////////

if (sr1Colour ==1 && sr2Colour==1){
  sequenceFinal1();
  ledPin = HIGH;
}
//  /////////////////////////////////////////////////////
// //Run final Sequence2
// /////////////////////////////////////////////////////

if (sr1Colour ==1 && sr2Colour==2){
  sequenceFinal2();
  ledPin = HIGH;
}
//  /////////////////////////////////////////////////////
// //Run final Sequence3
// /////////////////////////////////////////////////////

if (sr1Colour ==1 && sr2Colour==1){
  sequenceFinal3();
  ledPin = HIGH;
}
//  /////////////////////////////////////////////////////
// //Run final Sequence4
// /////////////////////////////////////////////////////

if (sr1Colour ==1 && sr2Colour==2){
  sequenceFinal4();
  ledPin = HIGH;
}
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister
 ////////////////////////////////////////////////////
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);// Change the start LED to 1
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister2
 ////////////////////////////////////////////////////
void updateShiftRegister2()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, leds);// Change the start LED to 8
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister3
 ////////////////////////////////////////////////////
void updateShiftRegister3()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);// Change the start LED to 1
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister4
 ////////////////////////////////////////////////////
void updateShiftRegister4()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, leds);// Change the start LED to 8
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister5
 ////////////////////////////////////////////////////
void updateShiftRegister5()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);// Change the start LED to 8
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister6
 ////////////////////////////////////////////////////
void updateShiftRegister6()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, leds);// Change the start LED to 8
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister7
 ////////////////////////////////////////////////////
void updateShiftRegister7()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);// Change the start LED to 8
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is updateShiftRegister8
 ////////////////////////////////////////////////////
void updateShiftRegister8()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, leds);// Change the start LED to 8
   digitalWrite(latchPin, HIGH);
}
/////////////////////////////////////////////////////
 //This is setBrightness
 ////////////////////////////////////////////////////
void setBrightness(byte brightness) // 0 to 255
{
  analogWrite(outputEnablePin, 255-brightness);
}
/////////////////////////////////////////////////////
 //This is Sequence 1
 ////////////////////////////////////////////////////
void sequence1(){
  Serial.println("button 1");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3){
     Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[0] && btnOn && (count >=3)) {
      Serial.println("Button 0 pressed again");
      count;
      leds = 0;
      setBrightness(255);
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
   sr1Colour = 1; //Set SR1 to green
 leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
/////////////////////////////////////////////////////
 //This is Sequence 2
 ////////////////////////////////////////////////////
void sequence2(){
  Serial.println("button 2");
  for (int i = 0; i < 4; i++)
  {
    bitSet(leds, i);
    updateShiftRegister2();
    delay(50);
    for (byte b = 0; b < 255; b++)
    {
      setBrightness(b);
      delay(20);
    }
    Serial.println(count);
    if(count>=3)
    {
      Serial.println("Count =");
      Serial.print(count);
      leds = 0;
      //for (int i = 0; i < 4; i++)
  {
    bitSet(leds, -5);
    updateShiftRegister2();
    delay(50);
      setBrightness(255);
  }
      count = 0;
      break;
    }
    if (justpressed[1] && btnOn && (count >=3)) {
      leds = 0;
      break;
    }
  }
  //bitSet(leds,0);
  //delay(1000);
   sr1Colour = 2; //Set SR1 to red
  
  leds = 0;
   //switch_value = 0;
  setBrightness(255);
}
274  Using Arduino / LEDs and Multiplexing / Re: Driving many Led's From Four Shift registers on: April 20, 2013, 09:07:13 am
So, what is your question?  You haven't specified if it works, nor anything that doesn't.
275  Using Arduino / LEDs and Multiplexing / Re: Sure 3208 problem on: April 20, 2013, 08:38:04 am
You need to show us how you have it wired, either by a schematic or a pic showing the details.  Also, post your code.
276  General Category / General Discussion / Re: CMUCAM4 / Arduino UNO on: April 19, 2013, 01:56:25 pm
Yes, the Arduino should power the CMUCAM4.  What have you done so far?

Have installed the library and looked at the examples?

http://www.cmucam.org/projects/cmucam4/wiki
http://www.cmucam.org/docs/cmucam4/arduino_api/
277  General Category / General Discussion / Re: CMUCAM4 / Arduino UNO on: April 19, 2013, 11:19:18 am
What research have you done? Google Arduino and cmucam4 turns many discussions.
278  Development / Other Software Development / Re: Using Arduino IDE with Notepad++, my approach on: April 19, 2013, 10:39:05 am
Just went through your tutorial and the only problem I am having is after saving a sketch in NPP, and select run>Arduino, it doesn't import anything into the Arduino IDE.
279  Using Arduino / Microcontrollers / Re: Allowed current thru AVR devices on: April 19, 2013, 09:18:47 am
Awesome post CrossRoads!!  I think you should post this in the playground and keep a link to it handy..
280  Using Arduino / Programming Questions / Re: Pin conflict - servos/easyVR on: April 19, 2013, 09:10:10 am
Quote
The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.

You can put the servos on whatever pins you want...

Quote
Pin 0 and 1 RX/TX are not in use, but they're only for the HW mode ?
 

I believe these are used for the serial port for uploading your code to the Arduino.  Do not use these if you don't need to.

Quote
i had to remove alot cause the forum only allows 9500 characters

You can attached the ino file from the "Additional Options.." link at the bottom of the post thread page.

Quote
This works fine, but i got a modular robot with 14 servos who needs the PWM-signal.

Your code has 15 servos..
281  Community / Website and Forum / Re: Advanced Searching? on: April 18, 2013, 09:02:57 am
Funny..  I guess you guys are the smart ones.  Can I be your friend?
282  Community / Website and Forum / Re: Advanced Searching? on: April 18, 2013, 12:06:38 am
Ah, so there it is.  Somewhere that nobody can find it. 
283  Using Arduino / General Electronics / Re: Hardware Layers on: April 17, 2013, 11:37:44 pm
Learn something new everyday.

Thanks guys. +1
284  Using Arduino / General Electronics / Re: False Advertising? on: April 17, 2013, 11:32:49 pm
It seems legit.  But have read that it doesn't work as intended...
285  Using Arduino / Microcontrollers / Re: Actuator control on: April 17, 2013, 11:27:07 pm
We would need to know what control box you have.  Type of actuators..  etc..
Pages: 1 ... 17 18 [19] 20 21 ... 49