Skip to content
Permalink
Browse files

Better I2C slave example

Added sid_player project
  • Loading branch information...
daitangio committed Apr 30, 2018
1 parent 683b840 commit ac47b5f35f9c0cb6ada743c095d97830d81b1d78
@@ -6,8 +6,11 @@
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 06 April 2015
// Also, this version support "bulk" sends but remember wire library implementation uses a 32 byte buffer
// so you cannot send more then 16 register commands (i.e. 32 bytes)

// Last revision April 2018
// Created 06 April 2015
// This example code is in the public domain.


@@ -16,40 +19,48 @@
#include <SID.h>
#include <String.h>
SID mySid;
bool ledOn=false;

void setup()
{
Wire.begin(23); // join i2c bus with address #23
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Wire.onReceive(receiveEvent); // register event
mySid.begin();
mySid.playTestIntro();
Serial.println("SID Slave Ready");
pinMode(LED_BUILTIN, OUTPUT); // TRUE ON ONBULK SEND
mySid.loadPiano(VOICE1_Right);
mySid.loadPiano(VOICE2_Left);
// mySid.playTestIntro();
}

void loop()
{
delay(100);
//Serial.println(".");
{
if(ledOn) {
digitalWrite(LED_BUILTIN, HIGH);
}else{
digitalWrite(LED_BUILTIN, LOW);
}
}

/** The I2C SID Interface is very simple: two unsigned bytes sent, register -> value
* The I2C is a blocking interface, so we must test SID Results.
* The I2C is a blocking interface.
* To speed up things the caller can send more then 2 bytes: we turn on the led 13 to signal this "bulk" mode
*
*/
void receiveEvent(int howMany)
{
while ( Wire.available()) // loop through all but the last
{
if( Wire.available() >2 ){
ledOn=true;
}else{
ledOn=false;
}
while ( Wire.available()) // loop through all
{
uint8_t reg = Wire.read();
uint8_t val = Wire.read();

mySid.set_register(reg,val);
Serial.print(reg);
Serial.print(F(" > "));
Serial.println(val);
uint8_t val = Wire.read();
mySid.set_register(reg,val);
}
}
// Local variables:
// mode: c++
// mode: auto-complete
// End:
// End:

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -0,0 +1,61 @@
/*
<!> Programmer = USBasp for arduino Nano ATmega328
Brian Tucker 1-5-2015
sid-arduino-lib:
https://code.google.com/p/sid-arduino-lib/
based SID player example program sets
the 25 SID/6581 registers at 50Hz (delay(19)=~50Hz)
The register data is created using the excellent app
"SIDDumper" from the SIDCog project:
SIDCog:
http://forums.parallax.com/showthread.php/118285-SIDcog-The-sound-of-the-Commodore-64-!-%28Now-in-the-OBEX%29
SIDDumper:
http://gadgetgangster.com/scripts/displayasset.php?id=361
For best results use an IRQ at 50 or 60Hz and set the registers programatically.
For info on how to make music with the SID chip and related registers
I recomend the e-magazine "Commodore Hacking":
http://www.ffd2.com/fridge/chacking/
Specifically the Rob Hubbard play subroutine as that is the code
all serious C64 SID musicians must understand.
convert the dump to number with : http://www.expertsetup.com/~brian/c64/JConverter.jar / http://softcollection.sytes.net/javaprog
*/

// Connect PIN 9 from your arduino Uno to audio output (+ ground to the other pin of the audio output)!

#include <avr/pgmspace.h> //used to store data in the flash rom
//#include "Alternative_Fuel_dmp.h" //RAW SID register data file in flash
//#include "Castlevania_64_Mixes_dmp.h" //RAW SID register data file in flash
//#include "Zelda_1_Dungeon_dmp.h" //RAW SID register data file in flash
//#include "Open_Groove_dmp.h"
//#include "Vibralux_dmp.h"
//#include "Visitors_dmp.h"
#include "marche_hiver_dmp.h"
//#include "/home/forgeot/ownCloud/arduino/sketches/_musique/sidTest/Commando.dmp.h"
//#include "/home/path/ownCloud/arduino/sketches/_musique/sidTest/Commando.dmp.h"

#include <SID.h> //
SID mySid; //

#define LED 13

void setup() {
mySid.begin();
digitalWrite(LED,HIGH);
}

void loop() {
for(uint16_t sidPointer=0;sidPointer<=sidLength;sidPointer++){
for(uint8_t sidRegister=0;sidRegister<=24;sidRegister++){
mySid.set_register(sidRegister, (pgm_read_byte(&sidData[(sidPointer+sidRegister)])));
};
//digitalWrite(LED,HIGH);
delay(19);
//digitalWrite(LED,LOW);
sidPointer=sidPointer+24;
};
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,9 @@
name=StereoSID
version=2.0.5
version=2.0.6
author=Christoph Haberer,Mario Patino,Giovanni Giorgi
maintainer=Giovani Giorgi
sentence=MOS6581 Stereo SID Emulator Arduino Library
paragraph=This library emulates the SID sound chip of the famous Commodore 64 with enhanched stereo support.
paragraph=This library emulates the SID sound chip of the famous Commodore 64 with enhanced stereo support.
category=Uncategorized
url=http://gioorgi.com/tag/stereosid/
architectures=avr
@@ -7,7 +7,10 @@ Stereo Effect by Giovanni Giorgi

Take a look also at
https://github.com/farvardin/C64-music/tree/master/sid_arduino
for a dump of common-used musics
for a dump of common-used musics.
I added the sid_player example from the faravdin source code for a demo of this
library capabilities.



Installation

0 comments on commit ac47b5f

Please sign in to comment.
You can’t perform that action at this time.