SPIの通信は、音源IC(Slave)とマイコン(Master)にそれぞれあるVcc,GNDの電源端子、同期クロックのSCKと接続対象のSlaveを選択するSS(Slave Select)、MasterからSlaveに信号を送るMOSI(Master Out Slave In)とSlaveからMasterに信号を送るMISO(Master In Slave Out)があり、合計6本の線で構成されます。
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(A1,INPUT);
}
void LED_ON_OFF(void) {
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
}
void loop() {
// put your main code here, to run repeatedly:
int a;
a=digitalRead(A1);
if(A==1){
LED_ON_OFF();
}else{
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
int sokudo(int d, int s) {
int a;
a=d/s;
return a;
}
void loop() {
// put your main code here, to run repeatedly:
int d;
d=105;
s=100;
x=sokudo(d,s);
Serial.println(x);
}
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps
pinMode(11,OUTPUT);
}
// step 1: instruct sensor to read echoes
Wire.beginTransmission(112); // transmit to device #112 (0x70)
// the address specified in the datasheet is 224 (0xE0)
// but i2c adressing uses the high 7 bits so it's 112
Wire.write(byte(0x00)); // sets register pointer to the command register (0x00)
Wire.write(byte(0x51)); // command sensor to measure in "centimeters" (0x51)
// use 0x51 for centimeters
// use 0x52 for ping microseconds
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delay(20); // datasheet suggests at least 65 milliseconds
// step 3: instruct sensor to return a particular echo reading
Wire.beginTransmission(112); // transmit to device #112
Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02)
Wire.endTransmission(); // stop transmitting
// step 4: request reading from sensor
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112
// step 5: receive reading from sensor
if (2 <= Wire.available()) // if two bytes were received
{
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits
Serial.print(reading); // print the reading
Serial.println("cm");
void setup() {
// put your setup code here, to run once:
pinMode(11,OUTPUT);
}
void loop() {
int TIME=300;
int m[8]={262,294,330,349,392,440,494,523};
// put your main code here, to run repeatedly:
for(int i=0;i<8;i++){
tone(11,m[i],TIME) ;
delay(TIME) ;
}
}