In Ordnung, es scheint hier einige zu geben, die mit der Sache etwas anfangen können.
Der Aisler Link:
https://aisler.net/p/TQBQQATE
Der Thingiverse Link:
https://www.thingiverse.com/thing:5776940
Der Thingiverse Link zum Akku-Adapter den ich verwendet habe. Dieser ist nicht von mir:
https://www.thingiverse.com/thing:2976266
Der Code für die Arduino IDE bezogen auf den ATTiny85:
#define sockelvibration 60
#define maximalvibration 255
#define vibrationsstufen 5
const byte schrittgroesse = (maximalvibration - sockelvibration) / (vibrationsstufen + 1);
volatile byte vibrationsstufe = 0;
volatile unsigned long lastInterrupt;
#define debug false
#define debug2 false
#define motor 1
#define led 0
#define onOf 4
#define up 2
#define dwn 3
byte pwmTest = 0;
void Interrupt_config(){
//Löschen des Global Interrupt Enable Bits (I) im Status Register (SREG)
cli();
//Setze des Pin Change Interrupt Enable Bit
GIMSK |= (1 << PCIE);
//Setzen des Pin Change Enable Mask für PB2 - PB4
PCMSK |= (1 << PCINT2) | (1 << PCINT3) | (1 << PCINT4);
//Setzen des Global Interrupt Enable Bits (I) im Status Register (SREG)
sei();
}
void setup()
{
if( debug || debug2) {
Serial.begin(9600);
delay(500);
Serial.println("Starte debugging....PWM ist aus");
Serial.println(DDRB);
Serial.println(PORTB);
}
if(! debug && ! debug2){//nicht während des debuggens
DDRB =(1<<motor)|(1<<led);//Ausgabepins für PWM 0 und 1
digitalWrite(motor, LOW);
digitalWrite(led, LOW);
}
//PB2 ist Eingang
DDRB &= ~(1 << DDB2);
//PB3 ist Eingang
DDRB &= ~(1 << DDB3);
//PB4 ist Eingang
DDRB &= ~(1 << DDB4);
//PB2-PB4 Pullup ist eingeschaltet
PORTB |= (1 << PORTB2) | (1 << PORTB3) | (1 << PORTB4);
Interrupt_config();
if( debug ) {
Serial.print("DDRB: ");
Serial.println(DDRB, BIN);
Serial.print("PORTB: ");
Serial.println(PORTB, BIN);
}
}
//Aufruf der Interrupt Serviceroutine
ISR(PCINT0_vect)
{
cli(); // keine weiteren interrupts zulassen
unsigned long prellzeit = lastInterrupt+1000;//eine sekunde entprellen
lastInterrupt = millis();//der aktuelle ist nun der letzte
if(lastInterrupt < prellzeit) return;//entprellen
if ( debug ) Serial.println("Interrupt");
byte tastWertUp;
byte tastWertDwn;
byte tastWertOnOf;
byte pwmFreq;
/*
PB2 ist oben ->up
PB4 ist mitte ->onOf
PB3 ist unten ->dwn
*/
tastWertUp = (PINB & (1 << up)) >> up; //
tastWertOnOf = (PINB & (1 << onOf)) >> onOf; //
tastWertDwn = (PINB & (1 << dwn)) >> dwn; //
if (tastWertOnOf == 0) //wenn schalter zu gound geschlossen
{
if ( debug ) Serial.println("Interrupt onOf");
if(vibrationsstufe > 0) vibrationsstufe=0;
else if(vibrationsstufe == 0) {
//int delayAn = 0;
//while( ( ((PINB & (1 << onOf)) >> onOf) == 0) && (delayAn < 250)){
// if ( debug || debug2) Serial.println(delayAn);
// delayAn++;
// }
// if ((delayAn + 2) > 250) {
vibrationsstufe = 1;
// if ( debug ) Serial.println("An");
// }
}
}
if (tastWertUp == 0) //wenn schalter zu gound geschlossen
{
// mehr wenn möglich
if ( debug ) Serial.println("Interrupt up");
if (vibrationsstufe < vibrationsstufen && vibrationsstufe > 0 )
vibrationsstufe++;
}
if (tastWertDwn == 0) //wenn schalter zu gound geschlossen
{
// weniger wenn möglich
if ( debug ) Serial.println("Interrupt dwn");
if (vibrationsstufe > 1)
vibrationsstufe--;
}
pwmFreq = vibrationsstufe * schrittgroesse + sockelvibration ;
if(! debug){
if (vibrationsstufe == 0) {
if(! debug2 ) digitalWrite(motor,LOW);
if(! debug2 ) digitalWrite(led,LOW);
if( debug2 ) Serial.println("Aus");
}
else if(vibrationsstufe == vibrationsstufen){
if(! debug2 ) digitalWrite(motor,HIGH);
if(! debug2 ) digitalWrite(led,HIGH);
if( debug2 ) Serial.println("Max");
}
else {
pwmFreq = vibrationsstufe * schrittgroesse + sockelvibration ;
if(! debug2 ) analogWrite(motor, pwmFreq);
if(! debug2 ) analogWrite(led, pwmFreq);
if( debug2 ) Serial.print("PWM");
if( debug2 ) Serial.println(pwmFreq);
}
}
if ( debug ){
Serial.print("Vibrationsstufe: ");
Serial.print(vibrationsstufe);
Serial.print(" pwm: ");
Serial.println(pwmFreq);
}
sei();//Interrupts wieder freigeben
}
void loop() {
// put your main code here, to run repeatedly:
if ( debug ) {
Serial.print("Stufe: ");
Serial.println(vibrationsstufe);
delay(1000);
}
}