Show Posts
Pages: [1] 2 3 ... 26
1  Using Arduino / Programming Questions / Re: Expected unqualified-id before 'else' error on: September 09, 2014, 02:08:47 pm
Sorry about confusion...
It's a macro inside LED_2416.cpp (matrix driver library). I didn't write it.  
It supposed to translate Arduino pin numbers into hardware pins thus making digitawrites 100x faster. And it works, I just couldn't get this Macro to compile for some reason.
"/" are meant to be carryover to next line, without them whole thing will need to be written on single line.
And basically syntax is correct. If I make into a function (i.e. "void fWriteB(byte pin, byte val) ") it compiles, but doesn't give me fast pin write effect for some reason.  C++ macros apparently have their own syntax, and this is too advanced for me at this point smiley-sad
Fortunately I finally found substitution macro that works:
Code:
//Atmega328 Version of fastWrite - for pins 0-13
#define fWrite(_pin_, _state_) ( _pin_ < 8 ? (_state_ ?  PORTD |= 1 << _pin_ : \
PORTD &= ~(1 << _pin_ )) : (_state_ ?  PORTB |= 1 << (_pin_ -8) : PORTB &= ~(1 << (_pin_ -8)  )))

P.S. I'm writing sketch for my wearable LED display (w/ dual 24x16 LEDs) that I plan to show off at Maker's fair.  It was working fine with my ATMega1284p board, but that was too big to fit inside the case, so I'm rewriting it to run off small ATMega328 board.  I was stuck on this fastwrite for a while, thus my question. But it's good now!  Thank you all! smiley


All the # statements need to be at the top of the sketch.



Nope, #defines can show up anywhere, but they will only be visible to code below it in the file, which can be problematic on the arduino since it munges files together.
I think you both right. In main sketch it should be at the top, but if you including external library (like in my case), that library can have it anywhere.
2  Using Arduino / Audio / Re: Real time MIDI w/ music shield on: September 09, 2014, 01:04:31 pm
Glad you got it working! smiley
3  Using Arduino / Programming Questions / [RESOLVED] Expected unqualified-id before 'else' error on: September 09, 2014, 12:55:37 pm
I'm stuck on this error, have no clue why it's happening, syntax seems to be correct, all braces are in right places...
Code:
#define fWrite(pin, val) if (val) switch (pin) {     \
    case 0: PORTD |= 1<<0; break;       \
    case 1: PORTD |= 1<<1; break;       \
    case 2: PORTD |= 1<<2; break;       \
    case 3: PORTD |= 1<<3; break;       \
    case 4: PORTD |= 1<<4; break;       \
    case 5: PORTD |= 1<<5; break;       \
    case 6: PORTD |= 1<<6; break;       \
    case 7: PORTD |= 1<<7; break;       \
    case 8: PORTB |= 1<<0; break;       \
    case 9: PORTB |= 1<<1; break;       \
    case 10: PORTB |= 1<<2; break;      \
    case 11: PORTB |= 1<<3; break;      \
    case 12: PORTB |= 1<<4; break;      \
    case 13: PORTB |= 1<<5; break;      \
    } else switch (pin) {               \
    case 0: PORTD &= ~(1<<0); break;    \
    case 1: PORTD &= ~(1<<1); break;    \
    case 2: PORTD &= ~(1<<2); break;    \
    case 3: PORTD &= ~(1<<3); break;    \
    case 4: PORTD &= ~(1<<4); break;    \
    case 5: PORTD &= ~(1<<5); break;    \
    case 6: PORTD &= ~(1<<6); break;    \
    case 7: PORTD &= ~(1<<7); break;    \
    case 8: PORTB &= ~(1<<0); break;    \
    case 9: PORTB &= ~(1<<1); break;    \
    case 10: PORTB &= ~(1<<2); break;   \
    case 11: PORTB &= ~(1<<3); break;   \
    case 12: PORTB &= ~(1<<4); break;   \
    case 13: PORTB &= ~(1<<5); break;   \
    }
4  Using Arduino / General Electronics / Re: ATTiny85 SOIC Eagle footprint on: September 09, 2014, 10:55:03 am
Thanks guys!  I don't know any easy way to measure exact distances in Eagle so it's pretty impossible to see  sizes of existing packages. I will get Element14's library!
5  Using Arduino / Audio / Re: Real time MIDI w/ music shield on: September 09, 2014, 10:53:24 am
I haven't played with it for a long time. I think this sketch should work if you connected all the pins correctly. It will just play middle C note.
Code:
#include <SD.h>
#include <SPI.h>
#include <MusicPlayer.h>

void setup()
{
  Serial.begin(115200);
  midiInit();
 
  //player.midiWriteData(0xC0, 1, 0); // Select instrument
  middleC();
  //triggerNotes();
 // playMIDIMelody();
 
}
void loop()
{
  //player.play();
 
  //delay(500);
}

void triggerNotes() {
  for (int note = 30; note <87; note++) {
    player.midiNoteOn(0, note, 127);
    delay (50);
    player.midiNoteOff(0, note, 127);
    delay (50);
  }
 
}

// Play one note for all instruments in bank GM1
void middleC(){
  setMIDIBank (1);
  for (int i=0;i<127;i++) {
    Serial.print ("Playing instrument: ");
    Serial.println (i);
    player.midiWriteData(0xC0, i, 0); // Select instrument
    player.midiNoteOn(0, 60, 127); // Play C4
    delay (1000);
    player.midiNoteOff(0, 60, 127); // Stop playing C4
  }
}

void playMIDIMelody () {
  // Note numbers
  int C4=60,D4=62,E4=64,F4=65,G4=67,A4=69,B4=71,C5=72;
  int PP=0; //Pause
  int melody[] = {C4,C4,PP,G4,G4,PP,A4,A4,PP,G4,PP,PP,PP,PP,
                  F4,F4,PP,E4,E4,PP,D4,D4,PP,C4};
  // note durations: 4 = quarter note, 8 = eighth note, etc.:
  int noteDurations[] = { 8,8,8,8,8,4,
                        8,8,8,8,8,4,
                        8,8,8,8,8,4,
                        8,8,8,8,8,4,
                        8,8,8,8,8,4};
  player.midiWriteData(0xC0, 1, 0); // Select instrument
 
  for (int thisNote = 0; thisNote < 24; thisNote++) {
    if (melody[thisNote]==PP) // Pause
      delay (50);
   else {
      player.midiNoteOn(0, melody[thisNote], 127);
      delay (250);
      player.midiNoteOff(0, melody[thisNote], 127);
      Serial.println (melody[thisNote]);
    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
      delay (200);
    }
  }
 
 
}

// Initializes MIDI
void midiInit(){
  player.beginInMidiFmt();
  player.midiWriteData(0xB0, 0x07, 120); // Set MIDI channel volume
}

// Sets MIDI bank to GM1 or GM2. Takes values 1 or 2
void setMIDIBank(byte bank) {
 if (bank==1) player.midiWriteData(0xB0, 0, 0x00);  // Select bank GM1
 else player.midiWriteData(0xB0, 0, 0x78);  // Select bank GM2
}
6  Using Arduino / General Electronics / ATTiny85 SOIC Eagle footprint on: September 08, 2014, 11:02:55 pm
Eagle 6.x has various Atmel parts, many look like correct package, but they all different in size. Can someone tell me if there's an existing part that has same foot print as ATTiny85 SOIC version?
7  Using Arduino / Audio / Re: Real time MIDI w/ music shield on: September 08, 2014, 09:29:52 pm
Hi bratan, do you have a copy of your edited MusicPlayer.h? Can you share it with the group.
Thanks muchs
Sure here it is...
8  Using Arduino / General Electronics / Re: Ambient Light Sensor vs LDR on: September 03, 2014, 02:49:42 pm
Great, thanks for the link!
9  Using Arduino / General Electronics / Re: Ambient Light Sensor vs LDR on: September 03, 2014, 02:10:05 pm
Note: you might wish to revise your description of the circuit you posted. They don't agree.
Sorry about that, you are right, I revised it.

The circuit design will be similar to that for an LDR, but you MUST consult the data sheet, which has an example circuit and all the other information you will need to properly design the interface and interpret the results.
On DataSheet pg 6 there's a circuit, but I don't understand it. Is it internal circuit of the device?  What is Capacitor doing there?

EDIT: I think I understand more now. Device I'm talking about is Phototransistor (right?).  Application is probably the same as LDR, 10K resistor should work?  I'm building simple LED badge that will dim LED's (via AVR's PWM) when it's dark and make them brighter when it's a lot of ambient light. From what I'm reading Phototransistor sense light changes faster, but for my purpose I don't care that much. It's more important to have light sensor in SMD package, and I couldn't find any easily sourceable LDRs in SMD packages smiley
10  Using Arduino / General Electronics / Ambient Light Sensor vs LDR on: September 03, 2014, 01:39:53 pm
I'm building custom circuit that has this SMD Ambient Light Sensor: ALS-PT19-315C/L177/TR8
I never dealt with these before, but I did built stuff with LDRs.
Will circuit be same as for regular Light resistor?  Meaning AVR analog pin will read voltage from Ambient Light Sensor and will have 10K resistor between second lead of sensor and ground?
11  Using Arduino / General Electronics / Re: DS3231 purpose of 2 resistors? on: June 02, 2014, 10:44:12 am
It seems mad they no longer make the 8 pin package when all the extra 8 pins on the 16 pin package are just grounded.
Oh yeah good point, SO16 is what I can find anyway... BTW I can only find eagle library for SO16W (wide?) version. Is there much difference between SO16 and SO16W? 
12  Using Arduino / General Electronics / Re: DS3231 purpose of 2 resistors? on: June 02, 2014, 10:07:38 am
Seeing as the data sheet says:-
Quote
All N.C. (no connect) pins must be connect- ed to ground.
Then I would say yes it is.
Ah, I must be blind, sorry about that, it is there in bold font too!
Thanks Mike!
13  Using Arduino / General Electronics / Re: DS3231 purpose of 2 resistors? on: June 02, 2014, 10:02:34 am
Ah right! It's been a while, I forgot those need pullups smiley Thanks!
One more question. Is it absolutely necessary to connect all NC pins to the ground?
14  Using Arduino / General Electronics / DS3231 purpose of 2 resistors? on: June 02, 2014, 09:31:27 am
In DS3231 datasheet there's a mention of 2 resistors (Rpu). What is the purpose of those and how do I determine value?
I know it says Rpu=Tr/Cb, but I couldn't find what those Tr and Cb means, which confused me even more smiley-sad
15  Using Arduino / Audio / Re: Real time MIDI w/ music shield on: March 18, 2014, 03:41:08 pm
Ok I figured it out. MIDI works just fine...
Musicplayer.cpp (from Music_shield library) has function midiDemoPlayer() which can play notes, change banks, etc.
It was just a matter of moving midi functions from private to public in MusicPlayer.h file and then calling them from your sketch...
For example:
Code:
player.beginInMidiFmt();
player.midiWriteData(0xB0, 0x07, 120); // Set MIDI channel volume
player.midiWriteData(0xB0, 0, 0x00);  // Select bank GM1
player.midiWriteData(0xC0, 1, 0); // Select instrument (Piano)
player.midiNoteOn(0, 70, 127); // Play note (C4)
delay (1000);
player.midiNoteOff(0, 70, 127); // Stop playing note

Pages: [1] 2 3 ... 26