User interface - Online Offline LED and speaker
This commit is contained in:
		
							parent
							
								
									c64f2e44fa
								
							
						
					
					
						commit
						eadfe70f1d
					
				@ -5,6 +5,9 @@
 | 
			
		||||
#include <TimerOne.h>
 | 
			
		||||
 | 
			
		||||
// pinout config
 | 
			
		||||
const int pinLedOffline = 10; // out
 | 
			
		||||
const int pinLedOnline = 9; // out
 | 
			
		||||
const int pinSpeaker = 8; // out
 | 
			
		||||
const int pinData = 6; // out, host data
 | 
			
		||||
const int pinStatus = 7; // in, host status
 | 
			
		||||
const int clockPin = 5; // out, kbd clock
 | 
			
		||||
@ -22,6 +25,7 @@ volatile int data = 0;
 | 
			
		||||
int test = 0;
 | 
			
		||||
volatile int counter = 0;
 | 
			
		||||
int numbits = 10;
 | 
			
		||||
volatile int typedKey = -1;
 | 
			
		||||
 | 
			
		||||
// MODS >>>
 | 
			
		||||
// [1] send debug scancode information to serial port
 | 
			
		||||
@ -31,7 +35,7 @@ bool modConsoleLog = true;
 | 
			
		||||
// ----------
 | 
			
		||||
// KBD Output
 | 
			
		||||
// ----------
 | 
			
		||||
volatile long lastChange = 0;
 | 
			
		||||
volatile long lastChange = -100000;
 | 
			
		||||
volatile int x = 0;
 | 
			
		||||
volatile int dataWord = 0;
 | 
			
		||||
volatile int dataState = 0;
 | 
			
		||||
@ -54,6 +58,7 @@ void sendKey(byte key) {
 | 
			
		||||
    dataDelay = 0;
 | 
			
		||||
    packetDelay = 0;
 | 
			
		||||
    packetTail = 15;
 | 
			
		||||
    typedKey = key;
 | 
			
		||||
    //Serial.print("Sending key "); Serial.println((int) key);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -365,6 +370,17 @@ void onTimerInterrupt()
 | 
			
		||||
  slaveClockStep = (slaveClockStep + 1) % slaveClockDivider;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------
 | 
			
		||||
// User Interface
 | 
			
		||||
// --------------
 | 
			
		||||
void updateOnlineLeds()
 | 
			
		||||
{
 | 
			
		||||
  long timeNow = millis();
 | 
			
		||||
  bool online = (lastChange > timeNow) || ((timeNow - lastChange) < 10000);
 | 
			
		||||
  digitalWrite(pinLedOffline, online ? LOW : HIGH);
 | 
			
		||||
  digitalWrite(pinLedOnline, online ? HIGH : LOW);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ----
 | 
			
		||||
// Main
 | 
			
		||||
// ----
 | 
			
		||||
@ -374,12 +390,17 @@ void setup(void)
 | 
			
		||||
  
 | 
			
		||||
  setupKeyMapping();
 | 
			
		||||
  
 | 
			
		||||
  pinMode(pinLedOffline, OUTPUT);
 | 
			
		||||
  pinMode(pinLedOnline, OUTPUT);
 | 
			
		||||
  pinMode(pinSpeaker, OUTPUT);
 | 
			
		||||
  pinMode(pinData, OUTPUT);
 | 
			
		||||
  pinMode(dataPin, INPUT);
 | 
			
		||||
  pinMode(outPin, OUTPUT);
 | 
			
		||||
  pinMode(clockPin, OUTPUT);
 | 
			
		||||
  pinMode(pinStatus, INPUT_PULLUP);
 | 
			
		||||
 | 
			
		||||
  digitalWrite(pinLedOffline, HIGH);
 | 
			
		||||
  digitalWrite(pinLedOnline, HIGH);
 | 
			
		||||
  digitalWrite(pinData, HIGH);
 | 
			
		||||
  digitalWrite(outPin, LOW);
 | 
			
		||||
 | 
			
		||||
@ -388,6 +409,23 @@ void setup(void)
 | 
			
		||||
  Timer1.initialize(timerDelay);
 | 
			
		||||
  Timer1.attachInterrupt(onTimerInterrupt);
 | 
			
		||||
 | 
			
		||||
  delay(500);
 | 
			
		||||
  tone(pinSpeaker, 650, 200);
 | 
			
		||||
  digitalWrite(pinLedOffline, LOW);
 | 
			
		||||
  digitalWrite(pinLedOnline, HIGH);
 | 
			
		||||
  delay(200);
 | 
			
		||||
  tone(pinSpeaker, 500, 200);
 | 
			
		||||
  digitalWrite(pinLedOffline, HIGH);
 | 
			
		||||
  digitalWrite(pinLedOnline, LOW);
 | 
			
		||||
  delay(200);
 | 
			
		||||
  digitalWrite(pinLedOffline, LOW);
 | 
			
		||||
  digitalWrite(pinLedOnline, LOW);
 | 
			
		||||
  delay(500);
 | 
			
		||||
 | 
			
		||||
  updateOnlineLeds();
 | 
			
		||||
  tone(pinSpeaker, 440, 200);
 | 
			
		||||
  delay(200);
 | 
			
		||||
 | 
			
		||||
  Serial.println("Keyboard ready");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -419,5 +457,13 @@ void loop(void)
 | 
			
		||||
  Serial.print("QWE "); Serial.println((int)k);
 | 
			
		||||
  if (qwe % 5 == 0) delay(2000);
 | 
			
		||||
  /**/
 | 
			
		||||
 | 
			
		||||
  updateOnlineLeds();
 | 
			
		||||
  if (typedKey != -1) {
 | 
			
		||||
      tone(pinSpeaker, 200 + typedKey, 100);
 | 
			
		||||
      typedKey = -1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  delay(5);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user