This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python による常微分方程式の数値解法 / Fehlberg 法 | |
from math import * | |
class Fehlberg: | |
def __init__(self, funcs, t0, inits, h, tol=1e-3): | |
self.funcs = funcs | |
self.t0 = t0 | |
self.inits = inits | |
self.h = h | |
self.numOfDiv = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python による常微分方程式の数値解法 / 古典的 Runge-Kutta 法 | |
class RK4: | |
def __init__(self, funcs, t0, inits, h, numOfDiv=1): | |
self.funcs = funcs | |
self.t0 = t0 | |
self.inits = inits | |
self.dim = len(funcs) | |
self.numOfDiv = numOfDiv | |
self.h = h / self.numOfDiv | |
self.f = [[None for i in range(self.dim)] for i in range(4)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I2C library for ATmega328P | |
*/ | |
#include "I2CClass.h" | |
#include "set_SCL_freq.h" | |
void I2CClass::waitForComplete(){ | |
loop_until_bit_is_set(TWCR, TWINT); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DS3231.h" | |
uint8_t bcd2dec(uint8_t bcd){return ((bcd >> 4) * 10) + (bcd & 0x0f);} | |
uint8_t dec2bcd(uint8_t dec){return ((dec / 10) << 4) + (dec % 10) ;} | |
uint8_t contain(uint8_t var, uint8_t min, uint8_t max){ | |
if (var < min){return min;} | |
else if(var > max){return max;} | |
else {return var;} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "LM75.h" | |
float LM75::getTemp(){ | |
int16_t tempData; | |
myI2C.start(); | |
myI2C.send(_ADDRESS_W); | |
myI2C.send(TEMP_REGISTER); | |
myI2C.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "myI2C.h" | |
void myI2CClass::waitForComplete(){ | |
loop_until_bit_is_set(TWCR, TWINT); | |
} | |
void myI2CClass::enable(uint16_t div){ | |
// i2cビットレート=システムクロック÷(16 + 2 * TWBR * PrescalerValue)。 | |
// PrescalerValueは4にしておく。 | |
TWSR &= ~(1 << TWPS1); | |
TWSR |= (1 << TWPS0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <inttypes.h> | |
#include <util/delay.h> | |
#include "USART.h" | |
#include "myI2C.h" | |
#include "LM75.h" | |
int main(){ | |
initUSART(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include "mySPIv2.h" | |
void mySPIClass::selectSlave(uint8_t port, uint8_t pin){ | |
switch(port){ | |
case 'B': PORTB &= ~(1 << pin); break; | |
case 'C': PORTC &= ~(1 << pin); break; | |
case 'D': PORTD &= ~(1 << pin); break; | |
default : PORTB &= ~(1 << PB2); break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
extern "C" { | |
#include "USART.h" | |
} | |
#include "mySPIv2.h" | |
#include "AD8402.h" | |
int main(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include "AD8402.h" | |
#include "mySPIv2.h" | |
void AD8402::setChPos(uint8_t ch, uint8_t pos){ | |
mySPI.selectSlave(_port, _pin); | |
mySPI.tradeByte(ch - 1); | |
mySPI.tradeByte(pos); | |
mySPI.deselectSlave(_port, _pin); | |
NewerOlder