ArduinoPunkConsole

hi out there…
http://beavisaudio.com/projects/arduinopunkconsole/
want to give it a try and run into a couple of issues…
got the code from here:

compiling it gives me several errors,
BYTE is not supported anymore.
Serial:print should be Serial.write
the display i am using is serial
the lib is LiquidCrystal I2C
who can help

found that: BYTE keyword not supported in 1.0 but that does not help…

Did you read that?

All these

 Serial.print (254, BYTE);

should be changed to

Serial.write(254);

Just lose the

  , BYTE

and change print to write. Obvsly I hope, leaving the particular number in each such statement unchanged.

Please report back.

If you mean you did that and it still doesn't work, then tell us where else you made any changes to the software or hardware and wiring from what the inventor revealed.

a7

thats what i got right now:

/* ======================================================================
 Arduino Punk Console
 A simple programmable 8 step tone sequencer 
 by dano/beavisaudio.com
 Revs
 -----------------------------------
 15 Sept  djh  initial version
======================================================================*/
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

// Map all the input and output pins
#define AnalogInFrequency 1
#define AnalogInTempo 2
#define AnalogInDuration 0
#define DigitalOutSignal 11
#define DigitalInSwitch0 2
#define DigitalInSwitch1 3
#define DigitalInSwitch2 4
#define DigitalInSwitch3 5
#define DigitalInSwitch4 6
#define DigitalInSwitch5 7
#define DigitalInSwitch6 8
#define DigitalInSwitch7 9 
#define DigitalInStartStop 10
#define DigitalOutLED 12
// Set up the array for each step
int steps[] = {100,120,140,160,180,200,220,240};
// misc housekeeping
int duration = 50;
int pitchval = 1;
int fPlayMode = true;
int lastPushedStep = -1;
// Initialize the tempo
int tempo = 100;
void setup()
{ 
  // setup pin modes (Digital pins are input by default, but
  // I like to set 'em explicitly just so the code is clear.
  pinMode (DigitalInSwitch0, INPUT);
  pinMode (DigitalInSwitch1, INPUT);
  pinMode (DigitalInSwitch2, INPUT);
  pinMode (DigitalInSwitch3, INPUT);
  pinMode (DigitalInSwitch4, INPUT);
  pinMode (DigitalInSwitch5, INPUT);
  pinMode (DigitalInSwitch6, INPUT);
  pinMode (DigitalInSwitch7, INPUT);                
  pinMode (DigitalInStartStop, INPUT);
  pinMode (DigitalOutSignal, OUTPUT);  
  pinMode (DigitalOutLED, OUTPUT);
  // setup comms for the LCD display
  Serial.begin(9600);

  StartupMessage();
} 
void StartupMessage()
{
  
  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 0);         // move cursor to   (0, 0)
  lcd.print ("BEAVIS: Arduino");
  delay(300);
  Serial.write (254); 
  Serial.write (192);
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)
  lcd.print ("Punk Console!");
  delay (2000);
  lcd.init();
  lcd.print ("Beavis: APC");
}

void clearLCD()
{
  lcd.init(); // initialize the lcd
  Serial.write(254);
  Serial.write(1);
}

void loop() 
{
  // Main sequence loop  
  for (int i=0; i<8; i++)
  {   
    // Are we playing or stopping?
    fPlayMode = digitalRead (DigitalInStartStop);
    digitalWrite (DigitalOutLED, HIGH);
    // Check the Hardware
     readSwitches();
     readPots();

    // update the display
    updateDisplay();

    // Make the noise
    if (fPlayMode)
    {
      freqout (steps[i], duration);
    }
    digitalWrite (DigitalOutLED, LOW);

    // Pause between steps
    delay (tempo);       
  }
} 

void updateDisplay()
{
  lcd.init(); // initialize the lcd
  lcd.setCursor(0, 0);         // move cursor to   (0, 0) 
  lcd.print ("Beavis: APC");   
  Serial.write (254);
  Serial.write (192);
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)  
  lcd.print ("T:");
  lcd.print (tempo);
  lcd.print (" d:");
  lcd.print (duration);
 if (lastPushedStep != -1)
 {
    lcd.print ("*");
    lcd.print (lastPushedStep);
 }
}
// Read the current values of the pots, called from the loop.
void readPots ()
{
    tempo = (analogRead (AnalogInTempo) * 1.9);
    duration = (analogRead (AnalogInDuration));      
}
// Read the current values of the switches and
// if pressed, replace the switch's slot frequency
// by reading the frequency pot.
void readSwitches()
{
  // reset last pushed button number
  lastPushedStep = -1;

  // check switch 0, if pressed, get the current freq into step 0, etc. etc.
  if (digitalRead (DigitalInSwitch0) == HIGH)
  {
    steps[0] = analogRead(AnalogInFrequency);
    lastPushedStep = 1;
  }

  else if (digitalRead (DigitalInSwitch1) == HIGH)
  {
    steps[1] = analogRead(AnalogInFrequency);
    lastPushedStep = 2;
  }

  else if (digitalRead (DigitalInSwitch2) == HIGH)
  {
    steps[2] = analogRead(AnalogInFrequency);
    lastPushedStep = 3;
  }
  else if (digitalRead (DigitalInSwitch3) == HIGH)
  {
    steps[3] = analogRead(AnalogInFrequency);
    lastPushedStep = 4;
  }
  else if (digitalRead (DigitalInSwitch4) == HIGH)
  {
    steps[4] = analogRead(AnalogInFrequency);
    lastPushedStep = 5;
  }
  else if (digitalRead (DigitalInSwitch5) == HIGH)
  {
    steps[5] = analogRead(AnalogInFrequency);
    lastPushedStep = 6;
  }
  else if (digitalRead (DigitalInSwitch6) == HIGH)
  {
    steps[6] = analogRead(AnalogInFrequency);
    lastPushedStep = 7;
  }
  else if (digitalRead (DigitalInSwitch7) == HIGH)
  { 
    steps[7] = analogRead(AnalogInFrequency);
    lastPushedStep = 8;
  }
}


//freqout code by Paul Badger 
// freq - frequency value
// t - time duration of tone
void freqout(int freq, int t) 
{ 
  int hperiod;     //calculate 1/2 period in us 
  long cycles, i; 

  // subtract 7 us to make up for digitalWrite overhead - determined empirically 
  hperiod = (500000 / ((freq - 7) * pitchval));             

  // calculate cycles 
  cycles = ((long)freq * (long)t) / 1000;    // calculate cycles 
  for (i=0; i<= cycles; i++)
  {              // play note for t ms  
    digitalWrite(DigitalOutSignal, HIGH);  
    delayMicroseconds(hperiod); 
    digitalWrite(DigitalOutSignal, LOW);  
    delayMicroseconds(hperiod - 1);     // - 1 to make up for fractional microsecond in digitaWrite overhead 
  } 
}
 

did not have the pots and buttons and stuff up yet, just the arduino & serial lcd
at least the output at the display seems reasonable now

You can save a lot of repeated code by putting the switch pin numbers in an array instead of having one name per pin.

Are you sure you don't want to eliminate those eight external pull-down resistors by using pinMode(INPUT_PULLUP)? You would wire the switches between the switch pin and Ground. To do that, change:
pinMode (DigitalInSwitches[i], INPUT);
to:
pinMode (DigitalInSwitches[i], INPUT_PULLUP);
and change:
if (digitalRead (DigitalInSwitches[i]) == HIGH)
to:
if (digitalRead (DigitalInSwitches[i]) == LOW)

/* ======================================================================
  Arduino Punk Console
  A simple programmable 8 step tone sequencer
  by dano/beavisaudio.com
  Revs
  -----------------------------------
  15 Sept  djh  initial version
  ======================================================================*/
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

// Map all the input and output pins
const byte AnalogInDuration = A0;
const byte AnalogInFrequency = A1;
const byte AnalogInTempo = A2;
const byte DigitalInSwitches[] = {2, 3, 4, 5, 6, 7, 8, 9};
const byte DigitalInStartStop = 10;
const byte DigitalOutSignal = 11;
const byte DigitalOutLED = 12;
// Set up the array for pitch at each step
int steps[] = {100, 120, 140, 160, 180, 200, 220, 240};
// misc housekeeping
int duration = 50;
int pitchval = 1;
int fPlayMode = true;
int lastPushedStep = -1;
// Initialize the tempo
int tempo = 100;

void setup()
{
  // setup pin modes (Digital pins are input by default, but
  // I like to set 'em explicitly just so the code is clear.
  for (size_t i = 0; i < 8; i++)
    pinMode (DigitalInSwitches[i], INPUT);

  pinMode (DigitalInStartStop, INPUT);
  pinMode (DigitalOutSignal, OUTPUT);
  pinMode (DigitalOutLED, OUTPUT);
  // setup comms for the LCD display
  Serial.begin(9600);

  StartupMessage();
}
void StartupMessage()
{

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 0);         // move cursor to   (0, 0)
  lcd.print ("BEAVIS: Arduino");
  delay(300);
  Serial.write (254);
  Serial.write (192);
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)
  lcd.print ("Punk Console!");
  delay (2000);
  lcd.init();
  lcd.print ("Beavis: APC");
}

void clearLCD()
{
  lcd.init(); // initialize the lcd
  Serial.write(254);
  Serial.write(1);
}

void loop()
{
  // Main sequence loop
  for (int i = 0; i < 8; i++)
  {
    // Are we playing or stopping?
    fPlayMode = digitalRead (DigitalInStartStop);
    digitalWrite (DigitalOutLED, HIGH);
    // Check the Hardware
    readSwitches();
    readPots();

    // update the display
    updateDisplay();

    // Make the noise
    if (fPlayMode)
    {
      freqout (steps[i], duration);
    }
    digitalWrite (DigitalOutLED, LOW);

    // Pause between steps
    delay (tempo);
  }
}

void updateDisplay()
{
  lcd.init(); // initialize the lcd
  lcd.setCursor(0, 0);         // move cursor to   (0, 0)
  lcd.print ("Beavis: APC");
  Serial.write (254);
  Serial.write (192);
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)
  lcd.print ("T:");
  lcd.print (tempo);
  lcd.print (" d:");
  lcd.print (duration);
  if (lastPushedStep != -1)
  {
    lcd.print ("*");
    lcd.print (lastPushedStep);
  }
}

// Read the current values of the pots, called from the loop.
void readPots ()
{
  tempo = (analogRead (AnalogInTempo) * 1.9);
  duration = (analogRead (AnalogInDuration));
}

// Read the current values of the switches and
// if pressed, replace the switch's slot frequency
// by reading the frequency pot.
void readSwitches()
{
  // reset last pushed button number
  lastPushedStep = -1;

  for (size_t i = 0; i < 8; i++)
  {
    // check switch 0, if pressed, get the current freq into step 0, etc. etc.
    if (digitalRead (DigitalInSwitches[i]) == HIGH)
    {
      steps[i] = analogRead(AnalogInFrequency);
      lastPushedStep = i + 1;
    }
  }
}


//freqout code by Paul Badger
// freq - frequency value
// t - time duration of tone
void freqout(int freq, int t)
{
  int hperiod;     //calculate 1/2 period in us
  long cycles;

  // subtract 7 us to make up for digitalWrite overhead - determined empirically
  hperiod = (500000 / ((freq - 7) * pitchval));

  // calculate cycles
  cycles = ((long)freq * (long)t) / 1000;    // calculate cycles

  for (long i = 0; i <= cycles; i++)
  {
    // play note for t ms
    digitalWrite(DigitalOutSignal, HIGH);
    delayMicroseconds(hperiod);
    digitalWrite(DigitalOutSignal, LOW);
    delayMicroseconds(hperiod - 1);     // - 1 to make up for fractional microsecond in digitaWrite overhead
  }
}

thx for the advice & to be honest i do not know about much what i am doing here but following inspirations and instructions… so i didn´t knew about INPUT_PULLUP, in fact i ordred a couple of 20 resistors last night on ebay :wink: hope the additional hardware arrives these days in my postbox and i can start to set this thing up and give it a real try…

got it all wired and soldered, software up and running, guess the layout on the webpage got a bug, cause tempo pot is missing a +V connection (found one source which has it: http://www.interorganic.com.ar/josx/ArduinoPunkConsole.pdf) added that and seems to read tempo and duration, not sure about frequency till now… in general seems to be too slow? like the fastest speed is like 60bpm?

/* ======================================================================
  Arduino Punk Console
  A simple programmable 8 step tone sequencer
  by dano/beavisaudio.com
  Revs
  -----------------------------------
  15 Sept  djh  initial version
  ======================================================================*/
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

// Map all the input and output pins

const byte AnalogInDuration = A0;
const byte AnalogInFrequency = A1;
const byte AnalogInTempo = A2;
const byte DigitalInSwitches[] = {2, 3, 4, 5, 6, 7, 8, 9};
const byte DigitalInStartStop = 10;
const byte DigitalOutSignal = 11;
const byte DigitalOutLED = 12;

// Set up the array for pitch at each step

int steps[] = {100, 120, 140, 160, 180, 200, 220, 240};

// misc housekeeping

int duration = 50;
int pitchval = 1;
int fPlayMode = true;
int lastPushedStep = -1;

// Initialize the tempo

int tempo = 100;

void setup()
{
  
  // setup pin modes (Digital pins are input by default, but
  // I like to set 'em explicitly just so the code is clear.
  
  for (size_t i = 0; i < 8; i++)
  pinMode (DigitalInSwitches[i], INPUT_PULLUP);
  pinMode (DigitalInStartStop, INPUT_PULLUP);
  pinMode (DigitalOutSignal, OUTPUT);
  pinMode (DigitalOutLED, OUTPUT);
  
  // setup comms for the LCD display
  
  StartupMessage();
}
void StartupMessage()
{

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 0);         // move cursor to   (0, 0)
  lcd.print ("BEAVIS: Arduino");
  delay(300);
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)
  lcd.print ("Punk Console!");
  delay (2000);
  lcd.init();
  lcd.print ("Beavis: APC");
}

void clearLCD()
{
  
  lcd.init(); // initialize the lcd

}

void loop()
{
  
  // Main sequence loop
  
  for (int i = 0; i < 8; i++)
  {
    
  // Are we playing or stopping?
    
    fPlayMode = digitalRead (DigitalInStartStop);
    digitalWrite (DigitalOutLED, HIGH);
    
  // Check the Hardware
    
    readSwitches();
    readPots();

  // update the display
    
    updateDisplay();

  // Make the noise
    
    if (fPlayMode)
    {
      freqout (steps[i], duration);
    }
    digitalWrite (DigitalOutLED, LOW);

  // Pause between steps
    
    delay (tempo);
  }
}

void updateDisplay()
{
  lcd.init(); // initialize the lcd
  lcd.setCursor(0, 0);         // move cursor to   (0, 0)
  lcd.print ("Beavis: APC");
  lcd.setCursor(2, 1);         // move cursor to   (2, 1)
  lcd.print ("T:");
  lcd.print (tempo);
  lcd.print (" D:");
  lcd.print (duration);
  
  if (lastPushedStep != -1)
  
  {
    lcd.print ("*");
    lcd.print (lastPushedStep);
  }
}

  // Read the current values of the pots, called from the loop.

void readPots ()
{
  tempo = (analogRead (AnalogInTempo) * 1.9);
  duration = (analogRead (AnalogInDuration));
}

// Read the current values of the switches and
// if pressed, replace the switch's slot frequency
// by reading the frequency pot.

void readSwitches()
{
  // reset last pushed button number
  
  lastPushedStep = -1;

  for (size_t i = 0; i < 8; i++)
  {
  // check switch 0, if pressed, get the current freq into step 0, etc. etc.
    
    if (digitalRead (DigitalInSwitches[i]) == LOW)
    {
      steps[i] = analogRead(AnalogInFrequency);
      lastPushedStep = i + 1;
    }
  }
}


//freqout code by Paul Badger
// freq - frequency value
// t - time duration of tone

void freqout(int freq, int t)
{
  int hperiod;     //calculate 1/2 period in us
  long cycles;

  // subtract 7 us to make up for digitalWrite overhead - determined empirically
  
  hperiod = (500000 / ((freq - 7) * pitchval));

  // calculate cycles
  
  cycles = ((long)freq * (long)t) / 1000;    // calculate cycles

  for (long i = 0; i <= cycles; i++)
  {
    
  // play note for t ms
    
    digitalWrite(DigitalOutSignal, HIGH);
    delayMicroseconds(hperiod);
    digitalWrite(DigitalOutSignal, LOW);
    delayMicroseconds(hperiod - 1);     // - 1 to make up for fractional microsecond in digitaWrite overhead
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.