/***************************************************************************** * This program operates with LSI application board LS7190-9200-SH for evaluating * LSI LS9200 and LS7190 series parts. With interactive command from keyboard in * conjunction with Serial Monitor this program allows for setting the brightness * of two seperate strings of LEDs with the command Lnn where nn = 0 to 63 to * correspond to 64 levels of brightnesses. Another command Sx where x = 0 or 1, * causes the two strings of LEDs to sweep up and down in brightness automatically. * The command S1 causes the two strings to sweep synchronously in the same direction, * while command S0 causes the two strings to sweep in opposite directions with the two * brightnesses in exact inverse proportions. * Revised: 03/15/2022 *****************************************************************************/ // inslude the SPI library: #include #include const int dimSelectPin = 9; //low for non-reverse, high for reverse dimming const int slaveSelectPin = 10; //low for slave select const int bit_mask = 0x3f; //mask for recovering wiper address from received data const int wr_op = 0x40; //opcode for write = 0x40 int wr_tap; //wiper tap 2-digit address int wipertap; //address and WR opcode combined int wiperAdress; //current wiper tap address int tapPoint; //wiper tap address stored in EEPROM int funcRequest; //dim or sweep request int dirRequest; //sweep direction request int mode; //selected sweep or level mode int count; //dim level in sweep routine int count1; //dim level combined with WR op code char L; //keyboard response for brightness settin char S; //keyboard response for sweep void setup() { pinMode(dimSelectPin, OUTPUT); //set the dimSelectPin as an output pinMode(slaveSelectPin, OUTPUT); //set the slaveSelectPin as an output: SPI.beginTransaction(SPISettings(4000000,MSBFIRST,SPI_MODE0));//set the SPI mode=0, sck speed=4MHz and MSB first SPI.begin(); // initialize SPI Serial.begin(9600); } void loop() { delay(100); Begin: delay(500); Serial.print("Enter Lnn to set brightness level where nn is from 00 to 63:" "\n" "\n"); delay(500); Serial.print("Enter Sx for auto sweep, where x = 0 for reverse sweep and x = 1 for parallel sweep:" "\n" "\n"); delay(500); while (Serial.available() == 0){ } funcRequest = Serial.read(); //read function request if (funcRequest == 76) { setLevel(); } else if (funcRequest == 83) { Sweep(); } else goto Begin; } /*********************************************************************************************************/ int setLevel() { Serial.print("\n"); digitalWrite(dimSelectPin, LOW); //Each LED string has same level start: delay(100); while (Serial.available() == 0){ } wr_tap = Serial.parseInt() ; if (wr_tap > 63) {wr_tap = 63;} //truncate invalid entry to 63 max wipertap = (wr_op | wr_tap); //address and WR opcode combined digitalWrite(slaveSelectPin, LOW); //select chip for write delay(10); SPI.transfer(wipertap); //send opcode plus wiper address to chip digitalWrite(slaveSelectPin, HIGH); //de-select chip EEPROM.write (0,wr_tap); //save the wiper address in memory Serial.print("Brightness level selected = "); Serial.print( wr_tap); Serial.print(";" "\n" "\n"); return; } /*************Sweep brightness up and down*******************/ int Sweep(){ startS: Serial.print("\n"); delay(100); if (Serial.available() > 0) dirRequest = Serial.read(); //read function request if (dirRequest == 48) { dirRequest = 0; Serial.print("reverse sweep selected" "\n" "\n"); digitalWrite(dimSelectPin, HIGH); //Select reverse sweep goto actS; } else if (dirRequest >= 49) { dirRequest = 0; Serial.print("non-reverse sweep selected" "\n" "\n"); digitalWrite(dimSelectPin, LOW); //Select non-reverse sweep goto actS; } else goto startS; actS: while (Serial.available() == 0){ Serial.print("sweeping up" "\n"); delay(100); for (count = 0; count < 46; count++){ digitalWrite(slaveSelectPin, LOW); delay(10); count1 = (wr_op | count); SPI.transfer(count1); //sweep delay(10); digitalWrite(slaveSelectPin, HIGH); delay(50); //50 ms step delay } delay(2000); //2 sec dwell at maximum Serial.print("sweeping down" "\n"); for (count = 0; count < 39; count++){ digitalWrite(slaveSelectPin, LOW); delay(10); count1 = (wr_op | (46 - count)); SPI.transfer(count1); //sweep delay(10); digitalWrite(slaveSelectPin, HIGH); delay(50); } delay(2000); //2 second dwell at min goto actS; } Serial.print("Done sweeping" "\n" "\n"); return; } /************************************End sweep brightness up and down***********************/