Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Pages: [1]   Go Down
Author Topic: Convert from int to hex?  (Read 721 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm trying to get a value from my analog in and then convert it to hex so I can send a midi note.

I'm trying to do something like this but I get an error:

int lightPin = 0;

int lightLevel = analogRead(lightPin);

lightnote = map (lightLevel 0, 900, 0x3A, 0x6A);  <-this has an error!

Thanks in advance!
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
map (lightLevel 0,
It has an error, because it missses a comma
Logged

Per Arduino ad Astra

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, thanks!   Yep, just figured this out and then was about to delete the post.  Thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My program is not working.  Anyone have an example of how to take analog input and then convert it to hex so I can output it as midi notes?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We can't see your program, or know why it isn't working.
Any integer decimal value can be represented in hex.
« Last Edit: February 19, 2011, 04:33:27 pm by Groove » Logged

Per Arduino ad Astra

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry,  here it is:

/*
 MIDI note player
 
 This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
 If this circuit is connected to a MIDI synth, it will play
 the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.

 
 The circuit:
 * digital in 1 connected to MIDI jack pin 5
 * MIDI jack pin 2 connected to ground
 * MIDI jack pin 4 connected to +5V through 220-ohm resistor
 Attach a MIDI cable to the jack, then to a MIDI synth, and play music.

 created 13 Jun 2006
 modified 2 Jul 2009
 by Tom Igoe

 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/MIDI
 
 */
 
 int note;
 int lightPin = 0;
 int lightnote;
 //int hexnote;

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x3A; note < 0x6A; note ++) {
   
    int lightLevel = analogRead(lightPin);
   
    lightLevel = map (lightLevel, 0, 900, 5, 100);
   
    lightnote = map (lightLevel, 0, 900, 0x3A, 0x6A);
   
    lightnote = constrain (lightLevel, 0x3A, 0x4A);
   
    //hexnote = (lightnote, HEX);
   
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, lightnote, 0x7F);
    delay(lightLevel);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);   
   // delay(lightLevel);
  }
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.print(cmd, BYTE);
  Serial.print(pitch, BYTE);
  Serial.print(velocity, BYTE);
}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We can see your program, but don't know why you think it isn't "working"
Logged

Per Arduino ad Astra

Pages: [1]   Go Up
Arduino Forum upgrade scheduled for Monday, October 20th, 11am-4pm (CEST). Sorry for the inconvenience!
Jump to: