Blink without delay using User Defined Functions containing Port Manipulation


hello all,

having little trouble getting basic proof of concept working.

as can see have setup port manipulation in setup , declared 2 x user defined functions @ bottom column1on() , column1off()

i'd avoid using delays blink these ports on , off , trying user millis instead of delays

as can seen in github repo here: https://github.com/adambrackpool/7x7ledarray/blob/master/port_sketch_function_experimental/port_sketch_function_experimental.ino

in sketch declare lot of user defined functions , switch them delay() commands... trying away this.

please can tell why outputs turn on , stay on , going wrong code shown below:

many in advance


code: [select]

unsigned long previousmillis = 0;
unsigned long interval = 1000;

void setup() {
  // put setup code here, run once:

ddra |= b11111111; // sets pa 7 - 0 output (8)
ddrb |= b11111000; // sets pb 7 - 3 output (5)
ddrc |= b11111111; // sets pc 7 - 0 output (8)
ddrd |= b10001111; // sets pd 3 - 0 output (5)
ddre |= b00111000; // sets pe 5 - 3 output (3)
ddrg |= b00100111; // sets pg 5, 2, 1, 0 output (4)
ddrh |= b01111011; // sets ph 6, 5, 4, 3, 1, 0 output (6)
ddrj |= b00000011; // sets pj 1, 0 output (2)
ddrl |= b11111111; // sets pl 7 - 0 output (8)

// not touch pe0 or pe1 used serial data

}

void loop() {
  // put main code here, run repeatedly:
unsigned long currentmillis = millis();

if (currentmillis - previousmillis < interval) {
    column1on();
  }
  previousmillis = currentmillis;
  if (currentmillis - previousmillis > interval) {
    column1off();
  }
  previousmillis = currentmillis;
}

void column1on(){
  porte |= b00010000;porth |= b01000010;porta |= b00000010;portc |= b10000001;portl |= b00100000;
}

void column1off(){
  porte &= b11101111;porth &= b10111101;porta &= b11111101;portc &= b01111110;portl &= b11011111;
}

code: [select]
if (currentmillis - previousmillis < interval) {
    column1on();
  }
  previousmillis = currentmillis;


if previousmillis supposed represent last time did should update when thing happens. is, move last line there inside block if statement.


Arduino Forum > Using Arduino > Programming Questions > Blink without delay using User Defined Functions containing Port Manipulation


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'