
Music Box's Code
Dependencies: MusicEngine TSL2561 mbed
スイッチサイエンスマガジンのmbedで手作りオルゴール記事中で使用しているプログラムです。
main.cpp@0:0a09d6a8ee06, 2015-06-08 (annotated)
- Committer:
- switchscience
- Date:
- Mon Jun 08 05:58:14 2015 +0000
- Revision:
- 0:0a09d6a8ee06
Father's day gift
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switchscience | 0:0a09d6a8ee06 | 1 | /* |
switchscience | 0:0a09d6a8ee06 | 2 | * Copyright (c) 2015 Switch Science, Inc. |
switchscience | 0:0a09d6a8ee06 | 3 | * https://international.switch-science.com/ |
switchscience | 0:0a09d6a8ee06 | 4 | * |
switchscience | 0:0a09d6a8ee06 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
switchscience | 0:0a09d6a8ee06 | 6 | * you may not use this file except in compliance with the License. |
switchscience | 0:0a09d6a8ee06 | 7 | * You may obtain a copy of the License at |
switchscience | 0:0a09d6a8ee06 | 8 | * |
switchscience | 0:0a09d6a8ee06 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
switchscience | 0:0a09d6a8ee06 | 10 | * |
switchscience | 0:0a09d6a8ee06 | 11 | * Unless required by applicable law or agreed to in writing, software |
switchscience | 0:0a09d6a8ee06 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
switchscience | 0:0a09d6a8ee06 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
switchscience | 0:0a09d6a8ee06 | 14 | * See the License for the specific language governing permissions and |
switchscience | 0:0a09d6a8ee06 | 15 | * limitations under the License. |
switchscience | 0:0a09d6a8ee06 | 16 | */ |
switchscience | 0:0a09d6a8ee06 | 17 | |
switchscience | 0:0a09d6a8ee06 | 18 | #include "mbed.h" |
switchscience | 0:0a09d6a8ee06 | 19 | #include "MusicEngine.h" |
switchscience | 0:0a09d6a8ee06 | 20 | #include "TSL2561.h" |
switchscience | 0:0a09d6a8ee06 | 21 | |
switchscience | 0:0a09d6a8ee06 | 22 | |
switchscience | 0:0a09d6a8ee06 | 23 | I2C i2c( dp4,dp5); |
switchscience | 0:0a09d6a8ee06 | 24 | TSL2561 lum( i2c , TSL2561_ADDRESS_FLOAT ); // TSL2561 SDA, SCL (Data available every 400mSec) // TSL2561 SDA, SCL (Data available every 400mSec) |
switchscience | 0:0a09d6a8ee06 | 25 | |
switchscience | 0:0a09d6a8ee06 | 26 | |
switchscience | 0:0a09d6a8ee06 | 27 | MusicEngine Speaker(dp15); |
switchscience | 0:0a09d6a8ee06 | 28 | Serial pc(USBTX, USBRX); |
switchscience | 0:0a09d6a8ee06 | 29 | int brightness = 15; |
switchscience | 0:0a09d6a8ee06 | 30 | |
switchscience | 0:0a09d6a8ee06 | 31 | int main() |
switchscience | 0:0a09d6a8ee06 | 32 | { |
switchscience | 0:0a09d6a8ee06 | 33 | pc.baud(9600); |
switchscience | 0:0a09d6a8ee06 | 34 | |
switchscience | 0:0a09d6a8ee06 | 35 | while(1) { |
switchscience | 0:0a09d6a8ee06 | 36 | pc.printf("Illuminance: %+7.2f [Lux]\r\n", lum.lux()); |
switchscience | 0:0a09d6a8ee06 | 37 | if(lum.lux() > brightness) { |
switchscience | 0:0a09d6a8ee06 | 38 | Speaker.play("T120L4CDEFEDCREFGAGFERCR4CR4CR4CR4CDEFEDC"); |
switchscience | 0:0a09d6a8ee06 | 39 | wait(15); |
switchscience | 0:0a09d6a8ee06 | 40 | } |
switchscience | 0:0a09d6a8ee06 | 41 | wait(1); |
switchscience | 0:0a09d6a8ee06 | 42 | } |
switchscience | 0:0a09d6a8ee06 | 43 | } |