Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EALib I2S LM75B SDFileSystem mbed
TestShiftreg.cpp
00001 /* 00002 * Copyright 2013 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /****************************************************************************** 00018 * Includes 00019 *****************************************************************************/ 00020 00021 #include "mbed.h" 00022 #include "TestShiftreg.h" 00023 00024 /****************************************************************************** 00025 * Defines and typedefs 00026 *****************************************************************************/ 00027 00028 00029 /****************************************************************************** 00030 * Public Functions 00031 *****************************************************************************/ 00032 00033 TestShiftreg::TestShiftreg(PinName mosi, PinName miso, PinName sclk, PinName cs) : 00034 _spi(mosi, miso, sclk), _cs(cs) { 00035 00036 _cs = 1; // to get it in a known state 00037 output(0x00); 00038 } 00039 00040 bool TestShiftreg::runTest() { 00041 output(0x1); 00042 wait(0.1); 00043 output(0x2); 00044 wait(0.1); 00045 output(0x4); 00046 wait(0.1); 00047 output(0x8); 00048 wait(0.1); 00049 output(0x10); 00050 wait(0.1); 00051 output(0x20); 00052 wait(0.1); 00053 output(0x40); 00054 wait(0.1); 00055 output(0x80); 00056 wait(0.1); 00057 output(0x40); 00058 wait(0.1); 00059 output(0x20); 00060 wait(0.1); 00061 output(0x10); 00062 wait(0.1); 00063 output(0x8); 00064 wait(0.1); 00065 output(0x4); 00066 wait(0.1); 00067 output(0x2); 00068 wait(0.1); 00069 output(0x1); 00070 wait(0.1); 00071 output(0x0); 00072 return true; 00073 } 00074 00075 void TestShiftreg::output(uint8_t value) { 00076 _cs = 0; 00077 _spi.write(value); 00078 _cs = 1; 00079 } 00080
Generated on Sun Jul 17 2022 08:29:10 by
