Show Posts
Pages: [1] 2 3 ... 10
1  Using Arduino / Programming Questions / Re: Arduino dimmer just flashing and inputs are bad on: October 22, 2012, 01:20:59 pm
Thanks, but I optimize code later if I get everything working.
2  Using Arduino / Programming Questions / Arduino dimmer just flashing and inputs are bad on: October 22, 2012, 12:17:17 pm
Should this code work? Arduino Mega 2560. Solid state relay on PIN 30 and zero crossing input on PIN2 (interrupt 0).
requestValue should be between 0 and 255.
My lightbulb is just flashing about twice a second. If I change OCR3A to 1280 or 2560, then lightbulb is a lot dimmer but still flashing.

Code:
volatile int counterValue;
volatile int requestValue1;

boolean output_allowed = 1;
int ledstatus;
boolean ledstatusoff = 1;
boolean ledstatusred;
boolean ledstatusgreen;
boolean ledstatusblue;
boolean ledstatuswhite;
boolean ledstatuso;
boolean ledstatusr;
boolean ledstatusg;
boolean ledstatusb;
boolean ledstatusw;
boolean out14;
boolean out15;
boolean out16;
boolean out17;
boolean out18;
boolean out19;
boolean out20;
boolean out21;
boolean out22;
boolean out23;
boolean out24;
boolean out25;
boolean out26;
boolean out27;
boolean out28;
boolean out29;
boolean out30;
boolean out31;
boolean out32;
boolean out33;
boolean out34;
boolean out35;
boolean out36;
boolean out37;
void setup() {
  attachInterrupt(0, resetCounter, CHANGE);
  cli();                      //Disable global interrupts
  TCCR3A = 0;                 //Set register to 0
  TCCR3B = 0;                 //Set register to 0
  OCR3A = 640;                //Compare match register to get desired timer count
  TCCR3B |= (1 << WGM12);     //Turn on CTC mode
  TIMSK3 |= (1 << OCIE3A);    //Enable timer compare interrupt
  TCCR3B |= (1 << CS10);      //Start timer
  sei();                      //Enable global interrupts
  requestValue1 = 200;
  
  Serial.begin(9600);
  
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);
  pinMode(17, OUTPUT);
  pinMode(18, OUTPUT);
  pinMode(19, OUTPUT);
  pinMode(20, OUTPUT);
  pinMode(21, OUTPUT);
  pinMode(22, OUTPUT);
  pinMode(23, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(25, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(27, OUTPUT);
  pinMode(28, OUTPUT);
  pinMode(29, OUTPUT);
  pinMode(30, OUTPUT);
  pinMode(31, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(34, OUTPUT);
  pinMode(35, OUTPUT);
  pinMode(36, OUTPUT);
  pinMode(37, OUTPUT);
  
  pinMode(39, INPUT);
  pinMode(40, INPUT);
  pinMode(41, INPUT);
  pinMode(42, INPUT);
  pinMode(43, INPUT);
  pinMode(44, INPUT);
  pinMode(45, INPUT);
  pinMode(46, INPUT);
  pinMode(47, INPUT);
  pinMode(48, INPUT);
  pinMode(49, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  
  digitalWrite(39, LOW);
  digitalWrite(40, LOW);
  digitalWrite(41, LOW);
  digitalWrite(42, LOW);
  digitalWrite(43, LOW);
  digitalWrite(44, LOW);
  digitalWrite(45, LOW);
  digitalWrite(46, LOW);
  digitalWrite(47, LOW);
  digitalWrite(48, LOW);
  digitalWrite(49, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
}

ISR(TIMER3_COMPA_vect)
{
  counterValue++;
  counterValue &= 0xff;
  if (counterValue==requestValue1)
  {
    digitalWrite(30, HIGH);
  }
  else
  {
    digitalWrite(30, LOW);
  }
}

void resetCounter()
{
  counterValue=0;
}

void loop() {  
  boolean buttonState8 = 0;
  boolean lastButtonState8 = 0;
  
  buttonState8 = digitalRead(8);

  if (buttonState8 != lastButtonState8) {
    if (buttonState8 == HIGH) {
      if(out30==0){
        out30=1;
      } else if(out30==1){
        out30=0;
      }
    }
  }
  lastButtonState8 = buttonState8;
  
  if (output_allowed) {
    if(out14) {digitalWrite(14, HIGH); } else { digitalWrite(14, LOW); }
    if(out15) {digitalWrite(15, HIGH); } else { digitalWrite(15, LOW); }
    if(out16) {digitalWrite(16, HIGH); } else { digitalWrite(16, LOW); }
    if(out17) {digitalWrite(17, HIGH); } else { digitalWrite(17, LOW); }
    if(out18) {digitalWrite(18, HIGH); } else { digitalWrite(18, LOW); }
    if(out19) {digitalWrite(19, HIGH); } else { digitalWrite(19, LOW); }
    if(out20) {digitalWrite(20, HIGH); } else { digitalWrite(20, LOW); }
    if(out21) {digitalWrite(21, HIGH); } else { digitalWrite(21, LOW); }
    if(out22) {digitalWrite(22, HIGH); } else { digitalWrite(22, LOW); }
    if(out23) {digitalWrite(23, HIGH); } else { digitalWrite(23, LOW); }
    if(out24) {digitalWrite(24, HIGH); } else { digitalWrite(24, LOW); }
    if(out25) {digitalWrite(25, HIGH); } else { digitalWrite(25, LOW); }
    if(out26) {digitalWrite(26, HIGH); } else { digitalWrite(26, LOW); }
    if(out27) {digitalWrite(27, HIGH); } else { digitalWrite(27, LOW); }
    if(out28) {digitalWrite(28, HIGH); } else { digitalWrite(28, LOW); }
    if(out29) {digitalWrite(29, HIGH); } else { digitalWrite(29, LOW); }
    if(out30) {digitalWrite(30, HIGH); } else { digitalWrite(30, LOW); }
    if(out31) {digitalWrite(31, HIGH); } else { digitalWrite(31, LOW); }
    if(out32) {digitalWrite(32, HIGH); } else { digitalWrite(32, LOW); }
    if(out33) {digitalWrite(33, HIGH); } else { digitalWrite(33, LOW); }
    if(out34) {digitalWrite(34, HIGH); } else { digitalWrite(34, LOW); }
    if(out35) {digitalWrite(35, HIGH); } else { digitalWrite(35, LOW); }
    if(out36) {digitalWrite(36, HIGH); } else { digitalWrite(36, LOW); }
    if(out37) {digitalWrite(37, HIGH); } else { digitalWrite(37, LOW); }
  }
}

EDIT:
Got this. Interrupt pin didn't get its signal.
But now, requestValue=255 should be very dim and it is. 0 should be brightest, but it's not. Brightest seems to be around 120. requestValue around 60-100 is flickering. 40 and 20 are pretty dim, but I can see no difference in light output.
Can anybody give some advice, what could be improved?

Also inputs don't react on every push. It skips some button pushes. If I disable dimmer, everything is fine.
What could be causing this? I have many buttons and none of them is working fine on first press.
3  Using Arduino / Programming Questions / Re: WS2801 strips on different pins on: October 15, 2012, 12:52:14 pm
I did it with counter that increase every loop cycle and then used modulo to decide, when I should move to next step. Then I came here and You suggested the same thing. I think I somehow subconsciously read this thread. smiley-grin
Program without delay works with 1 strip. Actually I can't say it's without delay, because I use one delay in the end of loop. Otherwise my counter would increase too fast and I must use bigger numbers with modulo.
Now I should probably make WS2801 array and try to calculate functions for them.
4  Using Arduino / Programming Questions / Re: WS2801 strips on different pins on: October 10, 2012, 03:55:57 pm
I have 3 strips with different lengths. I want to use same color run for all of them. I want all strips start and finish at the same time. But if they are different length, they need to have different speeds. And without delay.
All strips must start from the beginning and go pixel after pixel next colour.
Like the first run in this video.
5  Using Arduino / Programming Questions / Re: WS2801 strips on different pins on: October 10, 2012, 02:33:52 pm
I have different strips on different pins. It's not one long strip.
I send 3 long strings of data, not one.
I could send all update commands at the same time.

Or I could also use some chip, that takes 1 SPI input and splits it to multiple outputs that I could configure.
Let's say I have 300 pixels.
1-300 goes to input.
1-100 data goes to output 1
101-200 data goes to output 2
210-300 data goes to output 3
6  Using Arduino / Programming Questions / Re: WS2801 strips on different pins on: October 10, 2012, 02:03:58 pm
I would like to do it without delay and all strips make the run together. Not one after the other.
7  Using Arduino / Programming Questions / Re: using arduino to open and close a circuit on: October 10, 2012, 02:02:42 pm
You should use 5V relay that draws less than 40mA. Or if relay draws more current, you should use a transistor to switch the relay from Arduino output.
8  Using Arduino / Programming Questions / Re: WS2801 strips on different pins on: October 10, 2012, 01:25:28 pm
I want to use colorWipe-like function but without delay. I want to light up all strips beginning from one end and filling up to the other.
I want to use one function, that takes each instance of the class from array maybe. What aray should I use and is it possible to put strip1, strip2 and strip3 in an array?
I'd also like, if it takes same amount of time with 100 pixels and with 25 pixels. 100 pixel strip must run 4 times faster.
I also want to be able to change speed, color. And make more cool functions if I can figure out something.
9  Using Arduino / Programming Questions / Re: WS2801 strips on different pins on: October 08, 2012, 02:03:48 am
WS2801 LED Strip.

I have 3 different strips with different lengths.
strip1 - 113 pixels on pins 2 and 3
strip2 - 46 pixels on pins 4 and 5
strip3 - 88 pixels on pins 6 and 7

If I want to use colorWipe function, I have to make 3 of them. Maybe I can use arrays of strips somehow?
It also uses delay and I have no idea how to get rid of it.

Some example code
Code:
#include "SPI.h"
#include "WS2801.h"

WS2801 strip1 = WS2801(113, 2, 3);
WS2801 strip2 = WS2801(46, 4, 5);
WS2801 strip3 = WS2801(88, 6, 7);

void setup() {
  strip.begin();
  strip.show();
}

void loop() {  
  colorWipe1(Color(255, 0, 0), 50);
  colorWipe2(Color(0, 255, 0), 50);
  colorWipe3(Color(0, 0, 255), 50);
}

void colorWipe1(uint32_t c, uint8_t wait) {
  int i;
  
  for (i=0; i < strip1.numPixels(); i++) {
      strip1.setPixelColor(i, c);
      strip1.show();
      delay(wait);
  }
}
void colorWipe2(uint32_t c, uint8_t wait) {
  int i;
  
  for (i=0; i < strip2.numPixels(); i++) {
      strip2.setPixelColor(i, c);
      strip2.show();
      delay(wait);
  }
}
void colorWipe3(uint32_t c, uint8_t wait) {
  int i;
  
  for (i=0; i < strip3.numPixels(); i++) {
      strip3.setPixelColor(i, c);
      strip3.show();
      delay(wait);
  }
}
uint32_t Color(byte r, byte g, byte b)
{
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}
10  Using Arduino / Programming Questions / WS2801 strips on different pins on: October 07, 2012, 01:57:44 pm
I want to have different strips on different pins.
Code:
WS2801 strip1 = WS2801(100, 2, 3);
WS2801 strip2 = WS2801(200, 4, 5);
WS2801 strip3 = WS2801(300, 6, 7);
And I want to make different programs run at the same time.
At the moment I have for loops for each strip and they run one after the other. I'd like if they run at the same time. All strips have different number of pixels.
Is it possible somehow?
11  Using Arduino / Programming Questions / Re: Potentially easy math problem - inverting a number in a range on: September 13, 2012, 11:40:38 pm
Easier:
Code:
servo1.write(pos);
servo2.write(180-pos);
12  Using Arduino / Programming Questions / Re: Two Arduinos, synchronize variables on: September 10, 2012, 03:55:41 am
1 way communication was working, but it had 1-2 second delay between pushing button on one Arduino and lighting a led on the other Arduino. I tried with 2 variables and both of them changed values.
Currently not working 2 way code isn't changing any variable.
I'm afraid I am doing something fundamentally wrong making it 2 way, but I can't figure out, what it is.
13  Using Arduino / Programming Questions / Re: Two Arduinos, synchronize variables on: September 10, 2012, 03:17:04 am
Any hints?
14  Using Arduino / Programming Questions / Re: Two Arduinos, synchronize variables on: September 09, 2012, 10:22:32 am
I got Easytransfer working only one way. Can't get both sending and both receiving.
I just try to listen input 8 and then light LED.

Code for one Arduino:
Code:
#include <Wire.h>
#include <EasyTransferI2C.h>

EasyTransferI2C ET;

byte out11;

struct SEND_DATA_STRUCTURE{
  byte out11;
};
struct RECEIVE_DATA_STRUCTURE{
  byte out11;
};

SEND_DATA_STRUCTURE txdata;
RECEIVE_DATA_STRUCTURE rxdata;

void setup(){
  Wire.begin(1);
  ET.begin(details(txdata), &Wire);
  ET.begin(details(rxdata), &Wire);
  Wire.onReceive(receive);
  pinMode(13, OUTPUT); 
  pinMode(8, INPUT);
}

void loop() {
  txdata.out11 = digitalRead(8);

  ET.sendData(2);
 
  if(ET.receiveData()){
    out11 = rxdata.out11;
    if(out11 == 1) {
      digitalWrite(13, HIGH);
    } else {
      digitalWrite(13, LOW);
    }
  }
}

void receive(int numBytes) {}
Other:
Code:
#include <Wire.h>
#include <EasyTransferI2C.h>

EasyTransferI2C ET;

byte out11;

struct SEND_DATA_STRUCTURE{
  byte out11;
};
struct RECEIVE_DATA_STRUCTURE{
  byte out11;
};

SEND_DATA_STRUCTURE txdata;
RECEIVE_DATA_STRUCTURE rxdata;

void setup(){
  Wire.begin(2);
  ET.begin(details(txdata), &Wire);
  ET.begin(details(rxdata), &Wire);
  Wire.onReceive(receive);
  pinMode(13, OUTPUT); 
  pinMode(8, INPUT);
}

void loop() {
  txdata.out11 = digitalRead(8);

  ET.sendData(1);
 
  if(ET.receiveData()){
    out11 = rxdata.out11;
    if(out11) {
      digitalWrite(13, HIGH);
    } else {
      digitalWrite(13, LOW);
    }
  }
}

void receive(int numBytes) {}
15  Using Arduino / Programming Questions / Re: Two Arduinos, synchronize variables on: September 08, 2012, 06:53:05 pm
I already have program that works on Arduino1. It uses some variables to set output status. Now I need to change those same variables with Arduino2 that has ethernet shield connected to it. I want to change output statuses with direct inputs on Arduino1 and ethernet requests on Arduino2. Arduino2 also must monitor those variables and output their statuses. Arduino1 should always have higher priority. If time between changing same variable on both Arduinos in less than 3 seconds, then change should work only on Arduino1. If Arduino1 changes output status and after 3 seconds Arduino2 changes the same output status, then Arduino2 should take priority. All physical outputs are on Arduino1 and it does not have spare pins. I could get serial or I2C link, but that's all I have. I can't connect ethernet module to Arduino1.
Pages: [1] 2 3 ... 10