質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

Q&A

1回答

1866閲覧

RTCをSAKURAに変更したい

asean

総合スコア7

Arduino

Arduinoは、AVRマイコン、単純なI/O(入出力)ポートを備えた基板、C言語を元としたArduinoのプログラム言語と、それを実装した統合開発環境から構成されたシステムです。

0グッド

0クリップ

投稿2017/05/27 14:21

編集2017/06/01 11:13

プログラムで使われている関数部分などをSAKURAのものにかえて使いたいと考えているのですがいまいちどうやればいいか理解できず教えていただけるとありがたいです
(http://www.instructables.com/id/TimeDuino-Arduino-based-clock-using-7-segment-dis/)
このプログラムをGRSAKURAで動かしたいと考えています

"/* Arduino Based - 7Seg Display Clock (4 Digits HH : MM)
Can be activated via sound through the microphone
Dev: Michalis Vasilakis // Date: 30/12/2015 // License: BY-NC-SA
More info soon at www.ardumotive.com
//Library

include "SevenSeg.h"

include <DS1302.h>

//Seven Seg and DS1302 init
SevenSeg disp (11,12,8,7,6,10,9); //Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
const int numOfDigits =4; //Number of 7 segments
int digitPins [numOfDigits]={3,4,5,13}; //CC(or CA) pins of segment
DS1302 rtc(0,1,2); // Init the DS1302
Time t; // Init a Time-data structure

//Constants
const int selectBT = A0; //Select - Set button at pin A0
const int changeBT = A1; //Change button at pin A1
const int showBT = A2; //Show time button at pin A2
const int mic = A3; //Microphone at pin A3
const int leds= A4; //Leds to seperate time from min HH : MM

//Variables
int hour;
int min;
String clock;
int number;
int count=0;
unsigned long cc=0;
int sound;
int flag=0;
int flag1=0;

void setup() {

//Define Pins as inputs or outputs:
pinMode(selectBT, INPUT_PULLUP);
pinMode(changeBT, INPUT_PULLUP);
pinMode(showBT, INPUT_PULLUP);
pinMode(min, INPUT);
pinMode(leds, OUTPUT);

// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

//Defines the number of digits to be "numOfDigits" and the digit pins to be the elements of the array "digitPins"
disp.setDigitPins ( numOfDigits , digitPins );
//Only for common cathode 7segments
disp.setCommonCathode();
//Control brightness (values 0-100);
disp.setDutyCycle(70);
disp.setTimer (2);
disp.startTimer ();

}

void loop()
{
sound = analogRead(mic);

if ((hour<=9) && (min>9)){
clock = '0' + String(hour) + String(min);

}
else if ((min<=9) && (hour>9)){
clock = String(hour) + '0' + String(min);
}
else if ((hour<=9) && (min<=9)){
clock = '0' + String(hour) + '0' + String(min);
}
else{
clock = String(hour) + String(min);
}

number = clock.toInt();

if (digitalRead(selectBT) == LOW){

delay(300);
count++;
if (count>2){
count=0;
rtc.setTime(hour, min, 0); // Set the hour to 12:00:00 (24hr format)
}
}

if (count>0){
if (digitalRead(changeBT) == LOW){
delay(300);
if (count == 1){
if (hour>22){
hour=0;
}
else{
hour++;
}
}
if (count == 2){
if (min>58){
min=0;
}
else{
min++;
}
}
}
}
else{
// Get data from the DS1302
t = rtc.getTime();
hour = t.hour;
min = t.min;
}
if ((digitalRead(showBT) == LOW) || (sound<445 || sound>485)){
delay(500);
//...ones, turn led on!
if ( flag == 0){
digitalWrite(leds, HIGH);
flag=1; //change flag variable
}
//...twice, turn led off!
else if ( flag == 1){
flag=0; //change flag variable again
digitalWrite(leds, LOW);
hideTime();
}
}
if (flag == 1){
showTime();
}
else{
}
}
void showTime(){
disp.write(clock);
}
void hideTime(){
disp.write(" ");
}
ISR( TIMER2_COMPA_vect ){
disp.interruptAction ();
}"

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

MasahikoHirata

2017/06/01 07:31

ソースが読みにくいです。整形したソースは"'"で囲むと見やすくなります。GR SAKURAにはタイマーが色々ついているのでRTCとしての場合を回答したいのですが。修正は可能ですか?
asean

2017/06/01 11:14

自分のほうで自動整形にかけてみました。これで読みにくかったら申し訳ありません。よろしくお願いいたします
MasahikoHirata

2017/06/02 04:02

正確には”マークダウン”機能でソースを投稿(修正可能)されて欲しいですね。 ヒントは https://teratail.com/help に書かれています。
coco_bauer

2017/06/02 05:52

どんな問題が起きているのですか? 何を解決したいのですか???
guest

回答1

0

SAKURA って、GR-SAKURA(http://gadget.renesas.com/ja/product/sakura.html)
の事ですか?
であれば、まずは、目的の事だけ聞いても泥縄になるので、
1.ハード、IDE、ライブラリの仕様、内容などを学習します。
⇒これが出来ていれば、今回の様な質問は、出ないはず。
2.Arduino と Arduino 周辺機器 には、5.0V系、3.3V系がある。
3.GR-SAKURA は、基本3.3V系で、一部の入出力ピンが、3.3/5.0V で使える様になっているに過ぎない。
⇒すぐには壊れないし、数ヵ月は壊れないかもだし、回路の作り方、使い方では直ぐに燃えるかもだし。
4.つまり、5.0V用液晶などは、そのまま使うと、問題を起こす物がある。
⇒GR-SAKURAの3.3/5.0V共用で使えるピンで足りない場合には、
電圧レベル変換基板や、簡易的には、抵抗で、適正な電圧にする必要があります。
5.GR-SAKURAのIDEにも種々サンプルがあるので、それらを学習します。
6.Arduino と、GR-SAKURA とで比較対象出来る様に、それぞれ1セットづつ用意して、変更を行っていきます。

投稿2017/06/08 02:11

daive

総合スコア2028

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問