일단계 파이썬 v1.0 (2020-DEC-10)

'프로그래밍언어.Lib > 파이썬' 카테고리의 다른 글

pyfirmata 기초  (0) 2019.12.02
ipython 의 매직명령어들  (0) 2016.10.18
ipython 기본 사용법  (0) 2016.10.18
MicroPython 개발자의 IoT 발표 (pyCon2016)  (0) 2016.09.27
윈도7에서 ipython 설치하기  (0) 2016.01.07
Posted by 살레시오

댓글을 달아 주세요

// Advanced Microcontroller-based Audio Workshop
//
// http://www.pjrc.com/store/audio_tutorial_kit.html
// https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
// 
// Part 1-3: First "Hello World" program, play a music file
//
// WAV files for this and other Tutorials are here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav7;     //xy=91,352.00000953674316
AudioPlaySdWav           playSdWav6;     //xy=102,307.00000953674316
AudioPlaySdWav           playSdWav5;     //xy=108,261.0000286102295
AudioPlaySdWav           playSdWav3;     //xy=111.00000381469727,148.00000381469727
AudioPlaySdWav           playSdWav4;     //xy=113.00000381469727,210.0000057220459
AudioPlaySdWav           playSdWav1;     //xy=114,43.000003814697266
AudioPlaySdWav           playSdWav2;     //xy=114,95.00000190734863
AudioMixer4              mixer1;         //xy=308.0000114440918,118.00000381469727
AudioMixer4              mixer2;         //xy=473.0000534057617,227.0000057220459
AudioOutputI2S           i2s1;           //xy=640.0000991821289,266.0000276565552
AudioConnection          patchCord1(playSdWav7, 0, mixer2, 3);
AudioConnection          patchCord2(playSdWav6, 0, mixer2, 2);
AudioConnection          patchCord3(playSdWav5, 0, mixer2, 1);
AudioConnection          patchCord4(playSdWav3, 0, mixer1, 2);
AudioConnection          patchCord5(playSdWav4, 0, mixer1, 3);
AudioConnection          patchCord6(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord7(playSdWav2, 0, mixer1, 1);
AudioConnection          patchCord8(mixer1, 0, mixer2, 0);
AudioConnection          patchCord9(mixer2, 0, i2s1, 0);
AudioConnection          patchCord10(mixer2, 0, i2s1, 1);
// GUItool: end automatically generated code

AudioControlSGTL5000     sgtl5000_1;


///* Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14
//*/

/*// Use these with the Teensy 4.1 onboard SD card
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used
#define SDCARD_SCK_PIN   13  // not actually used
//*/

/*
//file names of guitar strings(gs):
const char* gs6[] ={"g600E.wav","g601F.wav","g602F#.wav","g603G.wav","g604G#.wav","g605A.wav","g606A#.wav","g607B.wav","g608C.wav","g609C#.wav","g610D.wav","g611D#.wav"};
const char* gs5[] ={"g500A.wav","g501A#.wav","g502B.wav","g503C.wav","g504C#.wav","g505D.wav","g506D#.wav","g507E.wav","g508F.wav","g509F#.wav"};
const char* gs4[] ={"g400D.wav","g401D#.wav","g402E.wav","g403F.wav","g404F#.wav","g405G.wav","g406G#.wav","g407A.wav","g408A#.wav","g409B.wav"};
const char* gs3[] ={"g300G.wav","g301G#.wav","g302A.wav","g303A#.wav","g304B.wav","g305C.wav","g306C#.wav","g307D.wav","g308D#.wav","g309E.wav"};
const char* gs2[] ={"g200B.wav","g201C.wav","g202C#.wav","g203D.wav","g204D#.wav","g205E.wav","g206F.wav","g207F#.wav","g208G.wav","g209G#.wav"};
const char* gs1[] ={"g100E.wav","g101F.wav","g102F#.wav","g103G.wav","g104G#.wav","g105A.wav","g106A#.wav","g107B.wav","g108C.wav","g109C#.wav"};
//C:C,E,G:{8,7,5,5,5,3}
//F:F,A,C:{1,0,3,2,1,1}
//*/

const char* gstr[] ={
 "g600E.wav"/*0*/,"g601F.wav"/*1*/,"g602F#.wav"/*2*/,"g603G.wav"/*3*/,"g604G#.wav"/*4*/
,"g500A.wav"/*5*/,"g501A#.wav"/*6*/,"g502B.wav"/*7*/,"g503C.wav"/*8*/,"g504C#.wav"/*9*/
,"g400D.wav"/*10*/,"g401D#.wav"/*11*/,"g402E.wav"/*12*/,"g403F.wav"/*13*/,"g404F#.wav"/*14*/
,"g300G.wav"/*15*/,"g301G#.wav"/*16*/,"g302A.wav"/*17*/,"g303A#.wav"/*18*/                
,"g200B.wav"/*19*/,"g201C.wav"/*20*/,"g202C#.wav"/*21*/,"g203D.wav"/*22*/,"g204D#.wav"/*23*/
,"g100E.wav"/*24*/,"g101F.wav"/*25*/,"g102F#.wav"/*26*/,"g103G.wav"/*27*/,"g104G#.wav"/*28*/
//아래는 1번 줄의 고음을 sampling한 것들
,"g105A.wav"/*29*/,"g106A#.wav"/*30*/,"g107B.wav"/*31*/,"g108C.wav"/*32*/,"g109C#.wav"/*33*/
,"g110D.wav"/*34*/,"g111D#.wav"/*35*/,"g112E.wav"/*36*/,"g113F.wav"/*37*/,"g114F#.wav"/*38*/,"g115G.wav"/*39*/
,"g116G#.wav"/*40*/,"g117A.wav"/*41*/,"g118A#.wav"/*42*/,"g119B.wav"/*43*/
};

//C:C,E,G:{8(C),0(E),3(G),12(E),15(G),20(C)}
//F:F,A,C:{1(F),5(A),8(C),13(F),17(A),20(C)}

//주의: 13번핀(LED)는 다른 용도(SCK)로 예약되어 있으므로 사용하면 안됨!
void setup() {
  
  Serial.begin(9600);
  
  // AudioMemoryUsageMax() 함수로 조사한 것보다 커야 한다
  // 이 예제의 경우에 7값이 찍혔다
  // https://www.pjrc.com/teensy/td_libs_AudioConnection.html
  AudioMemory(50);
  
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.7);
  
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      while(1);
    }
  }

  
  delay(1000);

/*
  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer1.gain(2, 0.5);
  mixer1.gain(3, 0.5);
  mixer2.gain(0, 0.5);
  mixer2.gain(1, 0.5);
  mixer2.gain(2, 0.5);
  */
}

#define DELAY 2
void loop() {
  //if (playSdWav1.isPlaying() == false) {
  
    Serial.println(AudioMemoryUsageMax());
/*
    playChord(8,0,3,12,15,20);// playChord(8,0,15,24,32,39);
    delay(random(5,10)*40); // wait for library to parse WAV info
    playChord(8,0,3,12,15,20);// playChord(8,0,15,24,32,39);
    delay(random(5,10)*40); // wait for library to parse WAV info
    playChord(8,24,27,32,36,39);//playChord(8,3,12,20,27,36);
    delay(random(5,10)*40); // wait for library to parse WAV info
    playChord(8,24,27,32,36,39);//playChord(8,3,12,20,27,36);
    delay(random(5,10)*40); // wait for library to parse WAV info
*/
    playChord(8,0,15,24,32,39);
    delay(random(5,10)*10); // wait for library to parse WAV info
    playChord(8,0,15,24,32,39);
    delay(random(5,10)*10); // wait for library to parse WAV info
    playChord(8,3,12,20,27,36);
    delay(random(5,10)*10); // wait for library to parse WAV info
    playChord(8,3,12,20,27,36);
    delay(random(5,10)*10); // wait for library to parse WAV info
  
  // do nothing while playing...
}

void playChord(byte s1, byte s2, byte s3, byte s4, byte s5, byte s6){
  
    playSdWav1.stop();//must be stopped first
    do {
      playSdWav1.play(gstr[s1]);
      delay(DELAY);
    } while (!playSdWav1.isPlaying());
    
    playSdWav2.stop();//must be stopped first
    do{
      playSdWav2.play(gstr[s2]);
      delay(DELAY);
    } while (!playSdWav2.isPlaying());
    
    playSdWav3.stop();//must be stopped first
    do {
      playSdWav3.play(gstr[s3]);
      delay(DELAY);
    } while (!playSdWav3.isPlaying());
    
    playSdWav4.stop();//must be stopped first
    do {playSdWav4.play(gstr[s4]);
    delay(DELAY);} while (!playSdWav4.isPlaying());
    
    playSdWav5.stop();//must be stopped first
    do {playSdWav5.play(gstr[s5]);
    delay(DELAY);} while (!playSdWav5.isPlaying());
    
    playSdWav6.stop();//must be stopped first
    do {playSdWav6.play(gstr[s6]);
    delay(DELAY);} while (!playSdWav6.isPlaying());
}

Posted by 살레시오

댓글을 달아 주세요

teensy audio design GUI

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav3;     //xy=74,367
AudioPlaySdWav           playSdWav1;     //xy=77,241
AudioPlaySdWav           playSdWav7;     //xy=78,597
AudioPlaySdWav           playSdWav4;     //xy=80,425
AudioPlaySdWav           playSdWav2;     //xy=81,303
AudioPlaySdWav           playSdWav6;     //xy=82,535
AudioPlaySdWav           playSdWav5;     //xy=86,476
AudioMixer4              mixer1;         //xy=291,316
AudioMixer4              mixer2;         //xy=449,424
AudioOutputI2S           i2s1;           //xy=626,430
AudioConnection          patchCord1(playSdWav3, 0, mixer1, 2);
AudioConnection          patchCord2(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord3(playSdWav7, 0, mixer2, 3);
AudioConnection          patchCord4(playSdWav4, 0, mixer1, 3);
AudioConnection          patchCord5(playSdWav2, 0, mixer1, 1);
AudioConnection          patchCord6(playSdWav6, 0, mixer2, 2);
AudioConnection          patchCord7(playSdWav5, 0, mixer2, 1);
AudioConnection          patchCord8(mixer1, 0, mixer2, 0);
AudioConnection          patchCord9(mixer2, 0, i2s1, 0);
AudioConnection          patchCord10(mixer2, 0, i2s1, 1);
// GUItool: end automatically generated code

AudioControlSGTL5000     sgtl5000_1;

// 오디오보드의 sd카드 슬롯을 이용
//#define SDCARD_CS_PIN    10
//#define SDCARD_MOSI_PIN  7
//#define SDCARD_SCK_PIN   14

// Teensy4.1보드의 sd카드 슬롯을 이용
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used
#define SDCARD_SCK_PIN   13  // not actually used


//기타와 관련된 상수들
#define TOUCHED 1
#define UNTOUCHED 0

#define STRING1 24
#define STRING2 25
#define STRING3 26
#define STRING4 27
#define STRING5 28
#define STRING6 29


void setup() {
  Serial.begin(115200);
  delay(1000);

  // put your setup code here, to run once:
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(1.0);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);

 
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  
  
  Serial.println("Ready.");
  
  pinMode(STRING1,INPUT);
  pinMode(STRING2,INPUT);
  pinMode(STRING3,INPUT);
  pinMode(STRING4,INPUT);
  pinMode(STRING5,INPUT);
  pinMode(STRING6,INPUT);
  
}


bool prevString1 = UNTOUCHED;
bool prevString2 = UNTOUCHED;
bool prevString3 = UNTOUCHED;
bool prevString4 = UNTOUCHED;
bool prevString5 = UNTOUCHED;
bool prevString6 = UNTOUCHED;

///*
#define TIME_WAIT_TO_PLAY 2
void forcePlay(AudioPlaySdWav *ptrPlaySdWav, const char *wav){
  ptrPlaySdWav->stop();
  do{
    ptrPlaySdWav->play(wav);
    delay(TIME_WAIT_TO_PLAY);
  } while(!ptrPlaySdWav->isPlaying());
}
//*/

void loop() {

  int tm=millis();
///*
  bool str1 = digitalRead(STRING1);
  if (prevString1==UNTOUCHED and str1==TOUCHED){
    forcePlay(&playSdWav1, "g100E.wav");
  }

  bool str2 = digitalRead(STRING2);
  if (prevString2==UNTOUCHED and str2==TOUCHED){
    forcePlay(&playSdWav2, "g200B.wav");
  }

  bool str3 = digitalRead(STRING3);
  if (prevString3==UNTOUCHED and str3==TOUCHED){
    forcePlay(&playSdWav3, "g300G.wav");
  }

  bool str4 = digitalRead(STRING4);
  if (prevString4==UNTOUCHED and str4==TOUCHED){
    forcePlay(&playSdWav4, "g400D.wav");
  }


  bool str5 = digitalRead(STRING5);
  if (prevString5==UNTOUCHED and str5==TOUCHED){
    forcePlay(&playSdWav5, "g500A.wav");
  }

  bool str6 = digitalRead(STRING6);
  if (prevString6==UNTOUCHED and str6==TOUCHED){
    forcePlay(&playSdWav6, "g600E.wav");
  }

  
  prevString1=str1;
  prevString2=str2;
  prevString3=str3;
  prevString4=str4;
  prevString5=str5;
  prevString6=str6;
//*/
  

/*
  playSdWav1.stop();
  do{
    playSdWav1.play("g600E.wav");
    delay(TIME_WAIT_TO_PLAY);
  } while(!playSdWav1.isPlaying());
*/
  
  Serial.print(millis()-tm);
  Serial.print(", S1:");Serial.print(str1);
  Serial.print(", S2:");Serial.print(str2);
  Serial.print(", S3:");Serial.print(str3);
  Serial.print(", S4:");Serial.print(str4);
  Serial.print(", S5:");Serial.print(str5);
  Serial.print(", S6:");Serial.print(str6);
  Serial.println();
  delay(10);
}

Posted by 살레시오

댓글을 달아 주세요