Добавлена команда для зуммера
This commit is contained in:
		
							
								
								
									
										161
									
								
								UsbTitle/UsbTitle.ino
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										161
									
								
								UsbTitle/UsbTitle.ino
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -1,78 +1,85 @@
 | 
			
		||||
#include <DigiUSB.h>
 | 
			
		||||
#include <EEPROM.h>
 | 
			
		||||
#include "LedControl.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 Now we need a LedControl to work with.
 | 
			
		||||
 pin 2 is connected to the DataIn 
 | 
			
		||||
 pin 1 is connected to the CLK 
 | 
			
		||||
 pin 0 is connected to LOAD 
 | 
			
		||||
 We have only a single MAX72XX.
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
LedControl lc=LedControl(2,1,0,1);
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  DigiUSB.begin();
 | 
			
		||||
  /*
 | 
			
		||||
   The MAX72XX is in power-saving mode on startup,
 | 
			
		||||
   we have to do a wakeup call
 | 
			
		||||
   */
 | 
			
		||||
  lc.shutdown(0,false);
 | 
			
		||||
  /* Set the brightness to a medium values */
 | 
			
		||||
  lc.setIntensity(0,0);
 | 
			
		||||
  /* and clear the display */
 | 
			
		||||
  lc.clearDisplay(0);
 | 
			
		||||
  delay(1000);  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  byte lastRead;
 | 
			
		||||
  byte lastCmd = 0xFF;
 | 
			
		||||
  byte value;
 | 
			
		||||
  DigiUSB.refresh();
 | 
			
		||||
  while (true) { // loop forever
 | 
			
		||||
    if (DigiUSB.available()) {
 | 
			
		||||
      // something to read
 | 
			
		||||
      lastRead = DigiUSB.read();
 | 
			
		||||
      if (lastRead >= 0x20 && lastRead<=0x7F){
 | 
			
		||||
        if (lastCmd == 0xFF){ //  Если ранее команд не было, значит считываем команду
 | 
			
		||||
          lastCmd = lastRead;
 | 
			
		||||
        }else{ // команда есть, операнд считали, выполняем
 | 
			
		||||
          if (lastCmd >=0x41 && lastCmd <=0x48){ // команда установки в сегменте нужного кода ABCDEFGH
 | 
			
		||||
            value = EEPROM.read(lastRead);
 | 
			
		||||
            lc.setRow(0, 7-(lastCmd-0x41), value+0x80);
 | 
			
		||||
          }else if (lastCmd >=0x61 && lastCmd <=0x68){ // команда установки в сегменте нужного кода abcdefgh
 | 
			
		||||
            value = EEPROM.read(lastRead);
 | 
			
		||||
            lc.setRow(0, 7-(lastCmd-0x61), value);
 | 
			
		||||
          }else if (lastCmd == 0x69){  // команда яркости i 0..9abcdef
 | 
			
		||||
            if (lastRead >=0x30 && lastRead <= 0x39){
 | 
			
		||||
              lc.setIntensity(0, lastRead-0x30);
 | 
			
		||||
            }else if (lastRead >=0x61 && lastRead <= 0x66){
 | 
			
		||||
              lc.setIntensity(0, lastRead-0x57);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x6C){ // команда количества разрядов l 0..7
 | 
			
		||||
            if (lastRead >=0x30 && lastRead <= 0x37){
 | 
			
		||||
              lc.setScanLimit(0, lastRead-0x30);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x78){ // команда очистки экрана x0
 | 
			
		||||
            if (lastRead == 0x30){
 | 
			
		||||
              lc.clearDisplay(0);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x73){ // команда s0..1
 | 
			
		||||
            if (lastRead == 0x30){
 | 
			
		||||
              lc.shutdown(0,false);
 | 
			
		||||
            }else{
 | 
			
		||||
              lc.shutdown(0,true);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          lastCmd = 0xFF;
 | 
			
		||||
        }
 | 
			
		||||
      }else{
 | 
			
		||||
        lastCmd = 0xFF;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // refresh the usb port for 10 milliseconds
 | 
			
		||||
    DigiUSB.delay(10);
 | 
			
		||||
  }
 | 
			
		||||
#include <DigiUSB.h>
 | 
			
		||||
#include <EEPROM.h>
 | 
			
		||||
#include "LedControl.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 Now we need a LedControl to work with.
 | 
			
		||||
 pin 2 is connected to the DataIn 
 | 
			
		||||
 pin 1 is connected to the CLK 
 | 
			
		||||
 pin 0 is connected to LOAD 
 | 
			
		||||
 We have only a single MAX72XX.
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
LedControl lc=LedControl(2,1,0,1);
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  DigiUSB.begin();
 | 
			
		||||
  /*
 | 
			
		||||
   The MAX72XX is in power-saving mode on startup,
 | 
			
		||||
   we have to do a wakeup call
 | 
			
		||||
   */
 | 
			
		||||
  lc.shutdown(0,false);
 | 
			
		||||
  /* Set the brightness to a medium values */
 | 
			
		||||
  lc.setIntensity(0,0);
 | 
			
		||||
  /* and clear the display */
 | 
			
		||||
  lc.clearDisplay(0);
 | 
			
		||||
  pinMode(3, OUTPUT);
 | 
			
		||||
  delay(1000); 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  byte lastRead;
 | 
			
		||||
  byte lastCmd = 0xFF;
 | 
			
		||||
  byte value;
 | 
			
		||||
  DigiUSB.refresh();
 | 
			
		||||
  while (true) { // loop forever
 | 
			
		||||
    if (DigiUSB.available()) {
 | 
			
		||||
      // something to read
 | 
			
		||||
      lastRead = DigiUSB.read();
 | 
			
		||||
      if (lastRead >= 0x20 && lastRead<=0x7F){
 | 
			
		||||
        if (lastCmd == 0xFF){ //  Если ранее команд не было, значит считываем команду
 | 
			
		||||
          lastCmd = lastRead;
 | 
			
		||||
        }else{ // команда есть, операнд считали, выполняем
 | 
			
		||||
          if (lastCmd >=0x41 && lastCmd <=0x48){ // команда установки в сегменте нужного кода ABCDEFGH
 | 
			
		||||
            value = EEPROM.read(lastRead);
 | 
			
		||||
            lc.setRow(0, 7-(lastCmd-0x41), value+0x80);
 | 
			
		||||
          }else if (lastCmd >=0x61 && lastCmd <=0x68){ // команда установки в сегменте нужного кода abcdefgh
 | 
			
		||||
            value = EEPROM.read(lastRead);
 | 
			
		||||
            lc.setRow(0, 7-(lastCmd-0x61), value);
 | 
			
		||||
          }else if (lastCmd == 0x69){  // команда яркости i 0..9abcdef
 | 
			
		||||
            if (lastRead >=0x30 && lastRead <= 0x39){
 | 
			
		||||
              lc.setIntensity(0, lastRead-0x30);
 | 
			
		||||
            }else if (lastRead >=0x61 && lastRead <= 0x66){
 | 
			
		||||
              lc.setIntensity(0, lastRead-0x57);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x6C){ // команда количества разрядов l 0..7
 | 
			
		||||
            if (lastRead >=0x30 && lastRead <= 0x37){
 | 
			
		||||
              lc.setScanLimit(0, lastRead-0x30);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x78){ // команда очистки экрана x0
 | 
			
		||||
            if (lastRead == 0x30){
 | 
			
		||||
              lc.clearDisplay(0);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x73){ // команда s0..1
 | 
			
		||||
            if (lastRead == 0x30){
 | 
			
		||||
              lc.shutdown(0,false);
 | 
			
		||||
            }else{
 | 
			
		||||
              lc.shutdown(0,true);
 | 
			
		||||
            }
 | 
			
		||||
          }else if (lastCmd == 0x7a){ // команда z0..f
 | 
			
		||||
            if (lastRead == 0x30){
 | 
			
		||||
              noTone(3);
 | 
			
		||||
            }else{
 | 
			
		||||
              tone(3, 100*(lastRead-0x30));
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
          lastCmd = 0xFF;
 | 
			
		||||
        }
 | 
			
		||||
      }else{
 | 
			
		||||
        lastCmd = 0xFF;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    // refresh the usb port for 10 milliseconds
 | 
			
		||||
    DigiUSB.delay(10);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user