アフィリエイト広告を利用しています
アクセスカウンター
ファン
<< 2018年07月 >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
最新記事
写真ギャラリー
カテゴリーアーカイブ
タグクラウド
月別アーカイブ
日別アーカイブ
最新コメント

広告

この広告は30日以上更新がないブログに表示されております。
新規記事の投稿を行うことで、非表示にすることが可能です。
posted by fanblog

2018年07月31日

【番外編8】ARDUINO STEP SEQUENCER / ブレッドボード

ARDUINO STEP SEQUENCER

次はArduinoでステップシーケンサーを作りたいと思ってググってたら、その名も"ARDUINO STEP SEQUENCER" のサイトを見つけた

"A simple programmable 8 step tone sequencer"とのことで、tone機能を使った8ステップシーケンサーらしい

まずはこのサイト(http://www.instructables.com/id/Arduino-Step-Sequencer/) を参考にブレッドボードで組んでみます
ARDUINO STEP SEQUENCER / ブレッドボード

ブレッドボードで組みやすいように少しパーツを変えて

(パーツ)
  1. タクトスイッチ X8
  2. スライドスイッチ X1
  3. LED X1
  4. 10KΩ 抵抗 X9
  5. 100K トリマポテンショメーター X4
  6. 8Ω 0.5W スピーカー X1

(1)配線

配線はこんな感じ

ARDUINO.STEP SEQUENCER.jpg

Arduino Step Sequencer.png

(2)スケッチ

スケッチは"ARDUINO STEP SEQUENCER"のサイト からそのままコピーして使うとエラーが出るので次の2箇所を書き換えて使う

 (修正前)
   Serial.print (254, BYTE);
   Serial.print (192, BYTE);

 (修正後)
   Serial.print (254);
   Serial.print (192);

で、修正したのがこれ↓

Arduino Step Sequencer
――――――――――(Arduino Step Sequencer)――――――――――
/* ======================================================================
Arduino Punk Console
A simple programmable 8 step tone sequencer
by dano/beavisaudio.com
Revs
-----------------------------------
15 Sept djh initial version
======================================================================*/
// 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);

}


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()
{
Serial.print (254);
Serial.print (192);
Serial.print ("T:");
Serial.print (tempo);
Serial.print (" d:");
Serial.print (duration);
if (lastPushedStep != -1)
{
Serial.print ("*");
Serial.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
}
}

―――――――――――――――――――――――――――

(3)実行

さあ、どうでしょう



操作がグダグダ・・・

音がちょっと単調ですが、ステップシーケンサーっぽくなってます

シンセとはまた違った面白さですが・・・思ったように操作できません・・・orz

あと、なんか変だなと思ってたんですが、LED表示が無いのでどのボタンの音がなっているのかわかりにくい

次回はこれを筐体に入れてみます

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 19:40| Comment(0) | TrackBack(0) | Auduino

2018年07月17日

【番外編6】Simple_Four-Step_Sequencer (S4SS) / ミント缶

Simple_Four-Step_Sequencer

前回Simple_Two-Step_SequencerというArduinoシンセを少し変えてSimple_Two-Step_Sequencerx2Simple_Five-Step_Sequencerというのにしてみた

これをAuduino_v5と同じようにミント缶に入れようと思ったのだけどスペース的にちょっと厳しい

それでSimple_Five-Step_Sequencerからオシレーターを1つ減らしてSimple_Four-Step_Sequencer (S4SS)をつくる
S4SS / ミント缶

パーツはArduino_v5 / ミント缶とほとんど同じだけどアンプユニットがない分だけ楽にできるはず

今回は電源スイッチとオーディオジャックも蓋につけたい

ちなみにスケッチはSimple_Five-Step_Sequencerのものをそのまま使って5つ目のオシレーター用ノブが無いだけ

(1)パーツ配置

パーツ
  1. ミント缶 x1
  2. Arduino NANO x1
  3. 19kΩ小型ポテンショメーター x6
  4. 12v電池+ケース x1
  5. ユニバーサル基板 x1
  6. 5ピン ステレオオーディオジャック x1
  7. トグルスイッチ x1
  8. 3mm LED x1
  9. 8Ω 2W スピーカー+スピーカーグリル x1

パーツの配置はこんな感じ

IMG_0047.jpg

(2)配線

前回のブレッドボードテストを元にユニバーサル基板に配線しました
上面
IMG_0035.jpg

下面
IMG_0036.jpg

(3)組み立て

では、ミント缶に組み入れます



できましたっっ

IMG_0031.jpg

Auduino_v5と区別がつきにくい・・・

ん〜、今回オシレーター1つ減らしたけど・・・やっぱりフルバーションも作ろっかな〜

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 19:36| Comment(0) | TrackBack(0) | Auduino

2018年07月10日

【番外編5】Simple_Two-Step_Sequencer (STSS) / ブレッドボード

Workshop: Basic Arduino Square-Wave Synth

前回までAuduino_v5を少し変えたりしてみたけど、これ以上は似たようなアイデアしかない

ほかのArduinoシンセも聴きたいので別のものを作ってみる

ググってたら"Workshop: Basic Arduino Square-Wave Synth"というサイトを見つけた

スクリーンショット 2018-06-26 14.53.28.png

何かのWorkshopネタらしいのでやりやすいかなと思ったけど、このシンセの音情報が見つけられなかったのでどんな音が出るのかわからない

で、とりあえずつくってから考える
1. Simple_Two-Step_Sequencer (STSS)

(1)配線

まずはブレッドボードでの配線

IMG_0015.jpg

Fritzingも

スクリーンショット 2018-06-26 9.07.35.png

今回、ポテンショは10kΩを使ってます

(2)スケッチ

スケッチは"Workshop: Basic Arduino Square-Wave Synth"からコピペ

Simple_Two-Step_Sequencer (STSS)
―――――――(Simple_Two-Step_Sequencer)―――――――
/*
6: Simple Two-Step Sequencer

This project combines pretty much everything from the previous tutorials.
It involves two oscillators, a status led, and tempo and volume pots.

*/

int speakerPin = 3; //connect speaker to pin 3
int ledPin = 11; //we'll use this pin for our status led
int oscillator1Pin = 0; //we can set frequency for first step here...
int oscillator2Pin = 1; //... and frequency for step 2 on this pin
int tempoPin = 2; //read tempo pot here

/*
The pinState variable checks if we are outputting a sound.
By default we can set it to LOW - meaning "off".
*/
int pinState = LOW;

long previousMicros; //count microSeconds to control frequency
int frequency; //variable to set frequency

long previousMillis; //count milliSeconds to control tempo
int tempo = 120; //default tempo is 120BPM

void setup(){
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void loop(){

//read from our analog pins and set our frequency limits
float oscillator1 = analogRead(oscillator1Pin);
oscillator1 = map(oscillator1, 0, 1023, 200, 2000);

float oscillator2 = analogRead(oscillator2Pin);
oscillator2 = map(oscillator2, 0, 1023, 200, 2000);

//read and set tempo limits
float tempo = analogRead(tempoPin);
tempo = map(tempo, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval = (1000/tempo)*60;

/*
We can't use the delay function in this case,
as it will freeze the sketch and disrupt the
oscillators.
Instead we use a method that counts milliSeconds,
compares it to our BPM, and switches between which
oscillator should be in use.
*/

//oscillator1
if(millis()-previousMillis > interval/2){
playTone(speakerPin, oscillator1, interval/2);
analogWrite(ledPin, LOW);
}
//oscillator 2
if(millis()-previousMillis < interval/2){
playTone(speakerPin, oscillator2, interval/2);
analogWrite(ledPin, tempo/4);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval){
previousMillis = millis();
}
}

/*
We use the same method here as above to
switch our outputPin on and off without having
to use delay() and thus keep everything running
smoothly.
*/

void playTone(int outputPin, int frequency, float tempo){

//this bit is new - it makes sure we're calculating the note's frequency correctly
float hperiod = (500000 / frequency) -7;
long cycles = ((frequency*tempo)/1000);
for(long i=0; i<=cycles; i++){
//we use frequency/2 because one LOW + one HIGH = one whole cycle
if(micros() - previousMicros > frequency/2){
previousMicros = micros();
if(pinState == LOW){
pinState = HIGH; //if the pin is already LOW, set it to HIGH
}
else{
pinState = LOW; //otherwise if it's HIGH, set it to LOW
}
digitalWrite(outputPin, pinState); //Write pinState to specified pin
}
}
}

――――――――――――――――――――――――――――

(3)実行

します



なるほど・・・昔のアニメの効果音みたいな音が出てきましたね・・・
思ってたんとちがーうって感じですがこれはこれで

で、これで終わっちゃうと"Workshop: Basic Arduino Square-Wave Synth"の重複情報を無駄に増やしただけなので少し変えます
2. Simple_Two-Step_Sequencerx2 (STSSx2)

Auduino_v5の時に2倍化しましたが今回もします

Arduino UNOには6つのアナログインプットがありますが、STSSはオシレーター2つとテンポ1つで合わせて3つのアナログインプットが使われています

今回はこれをもう1セット付け加えるだけです
というわけで名前はSimple_Two-Step_Sequencerx2

(1)配線

ブレッドボード上での配線はこんな感じ

IMG_0014.jpg
スクリーンショット 2018-06-26 9.06.23.png

(2)スケッチ

スケッチは少し書き足してこんな感じ

Simple_Two-Step_Sequencerx2
―――――(Simple_Two-Step_Sequencerx2 (STSSx2))―――――
/*
6': Simple Two-Step Sequencer x2

This project combines pretty much everything from the previous tutorials.
It involves two oscillators, a status led, and tempo and volume pots.

Changelog:
It involves four oscillators, a status led, and two tempo and volume pots.
*/

int speakerPin = 3; //connect speaker to pin 3
int ledPin = 11; //we'll use this pin for our status led
int oscillator1Pin = 0; //we can set frequency for first step here...
int oscillator2Pin = 1; //... and frequency for step 2 on this pin
int tempoPin1 = 2; //read tempo pot here
int oscillator3Pin = 3; //we can set frequency for first step here...
int oscillator4Pin = 4; //... and frequency for step 2 on this pin
int tempoPin2 = 5; //read tempo pot here

/*
The pinState variable checks if we are outputting a sound.
By default we can set it to LOW - meaning "off".
*/
int pinState = LOW;

long previousMicros; //count microSeconds to control frequency
int frequency; //variable to set frequency

long previousMillis; //count milliSeconds to control tempo
int tempo = 120; //default tempo is 120BPM

void setup(){
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void loop(){

//read from our analog pins and set our frequency limits
float oscillator1 = analogRead(oscillator1Pin);
oscillator1 = map(oscillator1, 0, 1023, 200, 2000);

float oscillator2 = analogRead(oscillator2Pin);
oscillator2 = map(oscillator2, 0, 1023, 200, 2000);

//read and set tempo1 limits
float tempo1 = analogRead(tempoPin1);
tempo1 = map(tempo1, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval1 = (1000/tempo1)*60;

//read from our analog pins and set our frequency limits
float oscillator3 = analogRead(oscillator3Pin);
oscillator3 = map(oscillator3, 0, 1023, 200, 2000);

float oscillator4 = analogRead(oscillator4Pin);
oscillator4 = map(oscillator4, 0, 1023, 200, 2000);

//read and set tempo2 limits
float tempo2 = analogRead(tempoPin2);
tempo2 = map(tempo2, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval2 = (1000/tempo2)*60;

/*
We can't use the delay function in this case,
as it will freeze the sketch and disrupt the
oscillators.
Instead we use a method that counts milliSeconds,
compares it to our BPM, and switches between which
oscillator should be in use.
*/

//oscillator1
if(millis()-previousMillis > interval1/2){
playTone(speakerPin, oscillator1, interval1/2);
analogWrite(ledPin, LOW);
}
//oscillator2
if(millis()-previousMillis < interval1/2){
playTone(speakerPin, oscillator2, interval1/2);
analogWrite(ledPin, tempo1/4);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval1){
previousMillis = millis();
}
//oscillator3
if(millis()-previousMillis > interval2/2){
playTone(speakerPin, oscillator3, interval2/2);
analogWrite(ledPin, LOW);
}
//oscillator4
if(millis()-previousMillis < interval2/2){
playTone(speakerPin, oscillator4, interval2/2);
analogWrite(ledPin, tempo2/4);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval2){
previousMillis = millis();
}
}

/*
We use the same method here as above to
switch our outputPin on and off without having
to use delay() and thus keep everything running
smoothly.
*/

void playTone(int outputPin, int frequency, float tempo){

//this bit is new - it makes sure we're calculating the note's frequency correctly
float hperiod = (500000 / frequency) -7;
long cycles = ((frequency*tempo)/1000);
for(long i=0; i<=cycles; i++){
//we use frequency/2 because one LOW + one HIGH = one whole cycle
if(micros() - previousMicros > frequency/2){
previousMicros = micros();
if(pinState == LOW){
pinState = HIGH; //if the pin is already LOW, set it to HIGH
}
else{
pinState = LOW; //otherwise if it's HIGH, set it to LOW
}
digitalWrite(outputPin, pinState); //Write pinState to specified pin
}
}
}

―――――――――――――――――――――――――――――

(3)実行

さて音の変化は2倍になったんでしょうか



う〜んなんとも・・・表現が広がった気はするけど2倍まではいかないかな

パラメーターをもう少しいじってみたほうがいいかな

とりあえずもう1つの案もやってみる
3. Simple_Five-Step_Sequencer (SFSS)

オシレーターのフリークエンシー調節に使ってるポテンショメーターの数を5つに増やしてみる

オシレーター5つとテンポ1つで6つのアナログインプットを埋めるという案

(1)配線

配線は上記2. Simple_Two-Step_Sequencerx2 (STSSx2)と同じ

(2)スケッチ

スケッチをこんな感じにして

Simple_Five-Step_Sequencer
―――――――(Simple_FIve-Step_Sequencer)―――――――
/*
6'': Simple Five-Step Sequencer

This project combines pretty much everything from the previous tutorials.
It involves two oscillators, a status led, and tempo and volume pots.

Changelog:
It involves five oscillators, a status led, and tempo and volume pots.
*/

int speakerPin = 3; //connect speaker to pin 3
int ledPin = 11; //we'll use this pin for our status led
int oscillator1Pin = 0; //we can set frequency for first step here...
int oscillator2Pin = 1; //... and frequency for step 2 on this pin
int oscillator3Pin = 2; //... and frequency for step 3 on this pin
int oscillator4Pin = 3; //... and frequency for step 4 on this pin
int oscillator5Pin = 4; //... and frequency for step 5 on this pin
int tempoPin = 5; //read tempo pot here

/*
The pinState variable checks if we are outputting a sound.
By default we can set it to LOW - meaning "off".
*/
int pinState = LOW;

long previousMicros; //count microSeconds to control frequency
int frequency; //variable to set frequency

long previousMillis; //count milliSeconds to control tempo
int tempo = 120; //default tempo is 120BPM

void setup(){
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void loop(){

//read from our analog pins and set our frequency limits
float oscillator1 = analogRead(oscillator1Pin);
oscillator1 = map(oscillator1, 0, 1023, 200, 2000);

float oscillator2 = analogRead(oscillator2Pin);
oscillator2 = map(oscillator2, 0, 1023, 200, 2000);

float oscillator3 = analogRead(oscillator3Pin);
oscillator3 = map(oscillator3, 0, 1023, 200, 2000);

float oscillator4 = analogRead(oscillator4Pin);
oscillator4 = map(oscillator4, 0, 1023, 200, 2000);

float oscillator5 = analogRead(oscillator5Pin);
oscillator5 = map(oscillator5, 0, 1023, 200, 2000);

//read and set tempo limits
float tempo = analogRead(tempoPin);
tempo = map(tempo, 0, 1023, 60, 1000);

//algorithm to convert tempo into BPM
float interval = (1000/tempo)*60;

/*
We can't use the delay function in this case,
as it will freeze the sketch and disrupt the
oscillators.
Instead we use a method that counts milliSeconds,
compares it to our BPM, and switches between which
oscillator should be in use.
*/

//oscillator1
if(millis()-previousMillis > interval/2){
playTone(speakerPin, oscillator1, interval/2);
analogWrite(ledPin, LOW);
}
//oscillator 2
if(millis()-previousMillis < interval/2){
playTone(speakerPin, oscillator2, interval/2);
analogWrite(ledPin, tempo/2);
}
//oscillator 3
if(millis()-previousMillis > interval/3){
playTone(speakerPin, oscillator3, interval/3);
analogWrite(ledPin, tempo/3);
}
//oscillator 4
if(millis()-previousMillis < interval/3){
playTone(speakerPin, oscillator4, interval/3);
analogWrite(ledPin, tempo/4);
}
//oscillator 5
if(millis()-previousMillis < interval/5){
playTone(speakerPin, oscillator5, interval/5);
analogWrite(ledPin, tempo/5);
}
//One cycle completed: reset our counter!
if(millis()-previousMillis > interval){
previousMillis = millis();
}
}

/*
We use the same method here as above to
switch our outputPin on and off without having
to use delay() and thus keep everything running
smoothly.
*/

void playTone(int outputPin, int frequency, float tempo){

//this bit is new - it makes sure we're calculating the note's frequency correctly
float hperiod = (500000 / frequency) -7;
long cycles = ((frequency*tempo)/1000);
for(long i=0; i<=cycles; i++){
//we use frequency/2 because one LOW + one HIGH = one whole cycle
if(micros() - previousMicros > frequency/2){
previousMicros = micros();
if(pinState == LOW){
pinState = HIGH; //if the pin is already LOW, set it to HIGH
}
else{
pinState = LOW; //otherwise if it's HIGH, set it to LOW
}
digitalWrite(outputPin, pinState); //Write pinState to specified pin
}
}
}

――――――――――――――――――――――――――――

(3)実行

これでもっとガチャガチャした音が出てくれればいいんだけど・・・



い、いけてるのか?

まあ、子供騙しなのでこれはこの辺で

で、せっかくなので次回このうちどれかを筐体に入れようかなと思います

ではまた〜


【永久保証付き】Arduino Uno

新品価格
¥3,240から


Raspberry Pi3 Model B ボード&ケースセット (Element14版, Clear)-Physical Computing Lab

新品価格
¥5,780から


Arduinoをはじめよう 第3版 (Make:PROJECTS)

新品価格
¥2,160から


Arduinoをはじめよう 互換キット UNO R3対応互換ボード 初心者専用実験キット 基本部品セット20 in 1 Arduino sidekick basic kit

新品価格
¥3,780から


Arduinoをはじめようキット

新品価格
¥4,310から


Arduino エントリーキット(Uno版)- Physical Computing Lab

新品価格
¥4,320から


タミヤ 楽しい工作シリーズ No.216 3ch RCロボット製作セット 70216

新品価格
¥6,327から


エレキット 水圧式ロボットアーム MR-9105

新品価格
¥4,560から


エレキット バトルタイタン2 MR-9101R

新品価格
¥3,163から


世界最小★OZO-010102-0102 World's Smallest SMART Robot - Dual Pack, 1 Crystal White & 1 Titanium Black 2 Bonus Limited-Edition Skins スマートロボット Ozobot社【並行輸入】

新品価格
¥6,000から


タミヤ 楽しい工作シリーズ No.211 アームクローラー工作セット 70211

新品価格
¥1,345から


タミヤ 楽しい工作シリーズ No.97 ツインモーターギヤーボックス (70097)

新品価格
¥587から


タミヤ 楽しい工作シリーズ No.106 4チャンネル・リモコンボックス (70106)

新品価格
¥1,118から


posted by riserobo: at 14:56| Comment(0) | TrackBack(0) | Auduino
検索
QRコード
RSS取得
プロフィール
riserobo:さんの画像
riserobo:
プロフィール
×

この広告は30日以上新しい記事の更新がないブログに表示されております。