Go Down

Topic: Addressing 23017/4051 using I2C Serial Interface & PROGMEM (Read 11880 times) previous topic - next topic

Grumpy_Mike

In place of:-
Code: [Select]
ledBits.portMode(0, 0b0000000000000000); // set all pins on chip 0 to output
Try
Code: [Select]

for(int i=0; i<16; i++)ledBits.portMode(i,OUTPUT);


macegr

portMode is actually 16 bits wide, so the original usage is OK.

The part where you go if(PadNote == 60) pattern |= 0x00; yada yada is later followed by if(PadNote == 60) pattern &= ~0x00; in the same unbroken chain of execution so OF COURSE it will never activate a pin.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Pitchoilcan

#77
May 22, 2012, 01:58 pm Last Edit: May 22, 2012, 04:25 pm by Pitchoilcan Reason: 1
"in the same unbroken chain of execution so" yada yada...
Quote
if(PadNote == 60) pattern |= 0x00; yada yada is later followed by if(PadNote == 60) pattern &= ~0x00; //OF COURSE it will never activate a pin

New approach.....
Quote
instead of a big bunch of if statements

Code: [Select]
if ((PadNote[i] >= 60) && (PadNote[i] <= 75)) {
   mcp.digitalWrite(PadNote[i]-60, HIGH);
}

Code: [Select]
if ((PadNote[i] >= 60) && (PadNote[i] <= 75)) {
   mcp.digitalWrite(PadNote[i]-60, LOW);
}

Quote
lights an LED number 0 to number 15 if the PadNote is between 60 and 75, so if PadNote is 65 it will light LED number 5.
================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

macegr

#78
May 25, 2012, 08:18 am Last Edit: May 25, 2012, 08:21 am by macegr Reason: 1
That new approach may actually blink an LED, but it'll be so fast you probably won't see it. You need to think about when you want to turn the LED on, when you want to turn the LED off, and why those events can't occur in the exact same function right after one another.

Overall...you need to just sit back, take a deep breath, absorb everything you've learned so far, and THINK. Slowly. Draw stuff on a piece of paper, with a pencil. Right now I see a lot of typing, rapid fire posting, instant changes to code made on poorly understood suggestions. It looks a lot like letting a balloon go in a small room. It bounces off all the walls and makes a lot of noise, but nothing much happens.

And remember...if someone comes in here and just solves your entire problem, top to bottom, that means they don't like you. In this forum we usually try to point people in the right direction, so they can pick up the skillset to solve other problems.
Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Go Up